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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 03 09:01:34 2025 UTC