|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2004-12-13 00:59 UTC] sniper@php.net
[2004-12-20 01:00 UTC] php-bugs at lists dot php dot net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 02:00:01 2025 UTC |
Description: ------------ Assume a class with overload-support. Now, if you use an instance of that class to __set/__get a property (of type string) an try to concatenate it with the return value of another function (which returns a string like session_id()) some strange things gonna happen. The actual return value (of the string-returning function, session_id() in this example) will be changed to '1'! (see code and the actual/expected results... notice, that the session_id may differ, but it's never expected to give '1' as a session_id) However, if a constant string (or if the return value is temporarily stored into another variable) is concatenated to the property, everthing works fine (see comments in the code). PHP configuration is: - Win 2000 SP4 - minixampp containing - Apache/2.0.48 (Win32) - PHP/4.3.4 Reproduce code: --------------- <?php class A { function A() { echo "A constructed<br>\n"; } function __get($key, &$value) { $value = $_SESSION[$key]; echo "__get was called with '$key' <br>\n"; return true; } function __set($key, $value) { $_SESSION[$key] = $value; echo "__set was called with '$key' = '$value' <br>\n"; return true; } } overload('A'); session_name("my_session"); session_start(); # make sure, a session is started $a =& new A(); $a->my_var = "test"; $res = $a->my_var.session_id(); # <- doesn't work properly! # the following one will work as expected # $res = $a->my_var."_constant_string"; # (produces output: "test_constant_string") # this one is ok, too: # $res = $a->my_var."".session_id(); echo "concat test :".$res."<br>\n"; echo "session id : ".session_id()."<br>\n"; ?> Expected result: ---------------- A constructed __set was called with 'my_var' = 'test' __get was called with 'my_var' concat-test : test31b4ed95c6d107d9e40368c160843d8e session id : 31b4ed95c6d107d9e40368c160843d8e Actual result: -------------- A constructed __set was called with 'my_var' = 'test' __get was called with 'my_var' concat-test : test1 session id : 31b4ed95c6d107d9e40368c160843d8e