php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #67922 Member function not found when dereferencing in write-context
Submitted: 2014-08-28 08:42 UTC Modified: 2014-08-28 21:53 UTC
From: arjen at react dot com Assigned: nikic (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: master-Git-2014-08-28 (Git) 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: arjen at react dot com
New email:
PHP Version: OS:

 

 [2014-08-28 08:42 UTC] arjen at react dot com
Description:
------------
Not sure about the summary, but I don't think this is intended behaviour (I double checked the uniform_variable_syntax and AST RFC) OR the error should be fixed.

Test script:
---------------
<?php

class B
{
	public function __get($name)
	{
		$this->__set($name, new C);
		return $this->$name;
	}

	public function __set($name, $value)
	{
		$this->$name = $value;
	}
}

class C
{
	public function test()
	{
		return new D;
	}
}

class D
{
	public $d;
}


$b = new B;
$b->c->test()->d = 'waa';
echo 'first call success' . PHP_EOL;

$b->c->test();
echo 'just a call to test() works' . PHP_EOL;

$b->c->test()->d = 'waa';
echo 'second call success' . PHP_EOL;

Expected result:
----------------
first call success
just a call to test() works
second call success

Actual result:
--------------
first call success
just a call to test() works

Fatal error: Call to a member function test() on unknown in /home/arjen/phpng/testcase.php on line 38

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-08-28 11:23 UTC] arjen at react dot com
Reduced testcase:

<?php

class C
{
	public function test()
	{
		return new stdClass;
	}
}

$b = new stdClass;
$b->c = new C;

$b->c->test()->d = 'waa';
 [2014-08-28 21:53 UTC] nikic@php.net
-Assigned To: +Assigned To: nikic
 [2014-08-28 22:20 UTC] nikic@php.net
Automatic comment on behalf of nikic
Revision: http://git.php.net/?p=php-src.git;a=commit;h=ae7e663330b241bf7906551f9e801223aa067dbf
Log: Fix bug #67922
 [2014-08-28 22:20 UTC] nikic@php.net
-Status: Assigned +Status: Closed
 [2016-07-20 11:40 UTC] davey@php.net
Automatic comment on behalf of nikic
Revision: http://git.php.net/?p=php-src.git;a=commit;h=ae7e663330b241bf7906551f9e801223aa067dbf
Log: Fix bug #67922
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 01 17:01:34 2025 UTC