From: lars_stegelitz at col dot wunderman dot com
Operating system: Windows 2000
PHP version: 4.3.4
PHP Bug Type: Class/Object related
Bug description: value from __get() concatenated to session_id() gives unexpected
results
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
--
Edit bug report at http://bugs.php.net/?id=28505&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=28505&r=trysnapshot4
Try a CVS snapshot (php5): http://bugs.php.net/fix.php?id=28505&r=trysnapshot5
Fixed in CVS: http://bugs.php.net/fix.php?id=28505&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=28505&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=28505&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=28505&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=28505&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=28505&r=support
Expected behavior: http://bugs.php.net/fix.php?id=28505&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=28505&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=28505&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=28505&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=28505&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=28505&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=28505&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=28505&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=28505&r=float