Bug #70790 [Opn->Fbk]: Nested __get calls in some cases.

From: Date: Fri, 30 Oct 2015 17:32:49 +0000
Subject: Bug #70790 [Opn->Fbk]: Nested __get calls in some cases.
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-196928@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=70790&edit=1

 ID:                 70790
 Updated by:         kalle@php.net
 Reported by:        phplists at stanvassilev dot com
 Summary:            Nested __get calls in some cases.
-Status:             Open
+Status:             Feedback
 Type:               Bug
 Package:            Scripting Engine problem
 Operating System:   OSX
 PHP Version:        7.0.0RC5
 Block user comment: N
 Private report:     N

 New Comment:

Hi,

Is this also the case for PHP5, as in the 5.6 branch?


Previous Comments:
------------------------------------------------------------------------
[2015-10-26 14:12:18] phplists at stanvassilev dot com

I was also surprised that the "recursive call" circuit-breaker flag is name-specific,
which doesn't allow me to do this:

class Foo {
	function __set($name, $value) {
		$this->{$name . '_was_set'} = $value;
	}
}

$f = new Foo;
$f->x = 123; // Out of memory error...

I feel that simply disallowing magic methods inside a magic methods without tracking *what name*
they're handling would be simpler, and faster in the runtime, right? Why can't it be
implemented this way.

------------------------------------------------------------------------
[2015-10-26 13:10:10] phplists at stanvassilev dot com

Description:
------------
A "magic property" call into __get shouldn't trigger nested __get, but in some cases
it does - namely, when you do isset on an array key of a non-existing property.

This is not a new behavior for PHP 7, PHP 5.6 also does this. But it's undesirable in general.



Test script:
---------------
class Abc {
	function __get($name) {
		echo $name . ", ";
		if (isset($this->shallow)); // Doesn't trigger __get.
		if (isset($this->deep['foo'])); // Triggers __get with name "deep".
		return 'value';
	}
}

$abc = new Abc();
echo $abc->trigger; // Produces output: trigger, deep, value.

Expected result:
----------------
It's expected isset() checks in __get won't produce nested __get calls in the same object
(the "deep" part of the output shouldn't exist).

Actual result:
--------------
Nested calls of __get occur.


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=70790&edit=1


Thread (6 messages)

« previous php.bugs (#196928) next »