php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #28505 value from __get() concatenated to session_id() gives unexpected results
Submitted: 2004-05-24 14:02 UTC Modified: 2004-12-20 01:00 UTC
Votes:2
Avg. Score:4.0 ± 1.0
Reproduced:2 of 2 (100.0%)
Same Version:0 (0.0%)
Same OS:2 (100.0%)
From: lars_stegelitz at col dot wunderman dot com Assigned:
Status: No Feedback Package: Class/Object related
PHP Version: 4.3.4 OS: Windows 2000
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: lars_stegelitz at col dot wunderman dot com
New email:
PHP Version: OS:

 

 [2004-05-24 14:02 UTC] lars_stegelitz at col dot wunderman dot com
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


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-12-20 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Oct 31 22:01:27 2024 UTC