php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #33710 ArrayAccess objects doen't initialize $this
Submitted: 2005-07-15 15:14 UTC Modified: 2005-07-19 09:34 UTC
Votes:2
Avg. Score:5.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: pornel at despammed dot com Assigned: dmitry
Status: Closed Package: Class/Object related
PHP Version: 5.1.0b3 OS: *
Private report: No CVE-ID:
 [2005-07-15 15:14 UTC] pornel at despammed dot com
Description:
------------
In object that implements ArrayAccess and accesses itself as array inside its own method, $this is not available ("Undefined variable: this")


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

class Foo implements ArrayAccess
{
	function offsetExists ($offset) {/*...*/}
 	function offsetGet ($offset) {/*...*/}
 	function offsetSet ($offset, $value) {/*...*/}
 	function offsetUnset ($offset) {/*...*/}

 	function fail()
 	{
	 	$this['blah'];
 	}

 	function succeed()
 	{
	 	$this;
	 	$this['blah'];
 	}

}

$bar = new Foo();
$bar->succeed();
$bar->fail();



Expected result:
----------------
No error. Both methods should work.

Actual result:
--------------
Notice: Undefined variable: this in c:\www\test.php5 on line 13

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-07-19 09:34 UTC] dmitry@php.net
Fixed in CVS HEAD and PHP_5_0.

The test case produces memory leaks in PHP_5_0.
These leaks are fixed in HEAD only.
 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Sun Apr 20 10:02:06 2014 UTC