php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #43322 $this[] not produces error
Submitted: 2007-11-18 13:15 UTC Modified: 2007-11-25 10:36 UTC
From: felipensp at gmail dot com Assigned:
Status: Wont fix Package: Scripting Engine problem
PHP Version: 6CVS-2007-11-18 (snap) OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: felipensp at gmail dot com
New email:
PHP Version: OS:

 

 [2007-11-18 13:15 UTC] felipensp at gmail dot com
Description:
------------
$this[] outside of class not produces error.

Reproduce code:
---------------
<?php

class foo {
    public function __construct() {
        $this[] = 1;
    }
}

// Fatal error: Cannot re-assign $this
// $this = new foo;

// Fatal error: Using $this when not in object context
// $this->a = new foo;

// Fatal error: Cannot use object of type foo as array
// new foo;

$this[] = new stdClass; // no error

Expected result:
----------------
Fatal error: Using $this when not in object context

Actual result:
--------------
No error

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-11-18 23:40 UTC] crrodriguez at suse dot de
<?php

$this[] = new stdClass; // no error

?>

happends as well on 5_3 as is wrong :( maybe dmitry can check this out.
 [2007-11-23 14:14 UTC] tony2001@php.net
There is nothing wrong in $this[] syntax, as it's used in ArrayAccess (see Zend/tests/bug33710.phpt for example), hence we cannot detect this in compile time.
But we can't check for $this in runtime, since that would be a major performance hit.

So this is clear "Won't fix" in my opinion.
 [2007-11-25 10:36 UTC] derick@php.net
What tony said.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 07:01:27 2024 UTC