Bug #79435 [Nab]: property assignment via call_user_func is inconsistent

From: Date: Mon, 30 Mar 2020 19:51:07 +0000
Subject: Bug #79435 [Nab]: property assignment via call_user_func is inconsistent
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-226353@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=79435&edit=1 ID: 79435 User updated by: ikarol at gomel dot iba dot by Reported by: ikarol at gomel dot iba dot by Summary: property assignment via call_user_func is inconsistent Status: Not a bug Type: Bug Package: Scripting Engine problem Operating System: Windows PHP Version: 7.2.29 Block user comment: N Private report: N New Comment: According to the docs(https://www.php.net/manual/en/language.oop5.basic.php), $this is a reference to the calling object. Though, there is a mention of a different behaviour for the static context, I'm sure it's only related to static(methods and properties), which is a different thing. Looking at the docs for static variables(https://www.php.net/manual/en/language.variables.scope.php#language.variables.scope.static), there is no mention of how $this is treated. As it only mentions that variables are saved by reference, I think it will be reasonable for someone to expect a special treatment for $this(considering it's not an ordinary variable, but pseudo-variable) Previous Comments: ------------------------------------------------------------------------ [2020-03-30 19:17:30] requinix@php.net > So it appears that $this is considered a variable As indicated by the $, yes. > rather than being resolved dynamically as a reference to the current calling > object in a context of local static variable How did you get that impression in the first place? If the documentation suggested so, that needs to be fixed. ------------------------------------------------------------------------ [2020-03-30 19:03:26] ikarol at gomel dot iba dot by So it appears that $this is considered a variable rather than being resolved dynamically as a reference to the current calling object in a context of local static variable. In my opinion this is not a straightforward behaviour. So $this either needs to be fixed(dynamic resolution), or this(behaviour) should be documented. ------------------------------------------------------------------------ [2020-03-30 18:23:28] requinix@php.net $testMap is initialized using the setC/setD methods on $this, which is $a1 at that time. ------------------------------------------------------------------------ [2020-03-30 15:55:55] ikarol at gomel dot iba dot by Description: ------------ Hi, so if property assignment is done through call_user_func, it will only work for the first call, but will fail for all next(see var_dump output in the example). Also, if I would assign through dynamic method name call ($this->{$methodName}($prop)), it will work fine. Test script: --------------- https://3v4l.org/ta03s Expected result: ---------------- All instances of A class should have defined(not-null)C properties Actual result: -------------- Only the first instance of A class has it defined, while other do not. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=79435&edit=1

« previous php.bugs (#226353) next »