php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #16614 Function called from class treats GLOBAL vars in different way...
Submitted: 2002-04-15 05:53 UTC Modified: 2002-06-01 10:07 UTC
Votes:4
Avg. Score:4.8 ± 0.4
Reproduced:3 of 3 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (33.3%)
From: daniel at webdevelopers dot cz Assigned:
Status: Closed Package: Class/Object related
PHP Version: 4.1.2 OS: Windows 2000, Windows XP
Private report: No CVE-ID: None
 [2002-04-15 05:53 UTC] daniel at webdevelopers dot cz
There is the line marked with '#*' in the following script. One line up you will find other line that should make the exactly same action (I think). Try to comment this line and uncomment line with '#*'. The output will differ. Why?

--- SCRIPT: START ---
<PRE><?php

class test {
	function test() {
		extfunc($this);
	}
}
#___________________________________________________________
function extfunc(&$ref) {
global $obj;
	$GLOBALS["obj"]=&$ref; # This is the same as '$obj=&$ref;'. Isn't it?
	#* $obj=&$ref;
}

#===========================================================
$test=new test();
var_dump($obj);

?></PRE>
--- SCRIPT: END ---

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-04-15 10:08 UTC] vmg at arachnion dot de
This error is reproducable for PHP 4.2.0rc1:

First version ($GLOBALS["obj"]=&$ref;) gives:

object(test)(0) {
}

Second version ($obj=&$ref;) gives:

NULL
 [2002-06-01 10:07 UTC] mfischer@php.net
Variables imported with global into the local function scope are actually references and therefore can't be assigned to another reference. $GLOBAL is a good workaround for this

However this isn't necessary for ZE2 because you don't need to pass objects by reference anymore (there's no shallowing coping going on anymore).
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 15:01:29 2024 UTC