php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #14645 Problems assigning by reference to globals
Submitted: 2001-12-21 10:38 UTC Modified: 2004-07-26 17:55 UTC
Votes:6
Avg. Score:2.8 ± 1.5
Reproduced:3 of 3 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (33.3%)
From: jan at tegtmeier dot de Assigned:
Status: Closed Package: Documentation problem
PHP Version: 4.1.0 OS: Linux
Private report: No CVE-ID: None
 [2001-12-21 10:38 UTC] jan at tegtmeier dot de
Hi PHP-Developer-Community,

here are
- a description of the bug,
- a short test-script and
- the configuration I used:

A global variable within a function is assigned something by reference . This value is only visible within this function - not in the main script, not in functions calls by this function.

The same assignment by value works fine.

This sounds buggy, but it's getting worse! Things get really confusing if you remove the comment before "#set_by_reference_GLOBALS();".

This function accesses the global variable over the $GLOBALS array. This assignment works, BUT: After this function is called, the other function I mentioned before that assigns by value does not work anymore for the rest of the script-session! (It only works if this line is commented out)!!!

=================[test.php]=================
<PRE><?
$global = "hello world";

function show($prefix)
{
	global $var;
	echo "$prefix: $var\r\n";
}

function set_by_reference()
{
	global $var, $global;
	$var = "[empty]";
	$var =& $global;
	show("var assigned by reference");
}

function set_by_value()
{
	global $var, $global;
	$var = "[empty]";
	$var = $global;
	show("var assigned by value");
}

function set_by_reference_GLOBALS()
{
	global $var, $global;
	$var = "[empty]";
	$GLOBALS["var"] =& $global;
	show("GLOBALS[var] assigned by reference");
}

#set_by_reference_GLOBALS();
set_by_reference();
set_by_value();

?></PRE>
=================[test.php]=================

==============[SYSTEM CONFIG]===============
System: Linux 2.4.16-SMP
Apache: 1.3.22
PHP: 4.1.0
Configure Params:
./configure
  --prefix=/usr/local/php
  --with-mysql=/usr
  --with-apache=/usr/src/packages/SOURCES/apache_1.3.22
  --with-sybase-ct=/usr/local/freetds
==============[SYSTEM CONFIG]===============

=================[php.ini]==================
[PHP]
engine = On
short_open_tag = On
asp_tags = Off
precision    =  14
y2k_compliance = Off
output_buffering = 4096
output_handler =
zlib.output_compression = Off
implicit_flush = Off
allow_call_time_pass_reference = Off
safe_mode = Off
safe_mode_gid = Off
safe_mode_include_dir =
safe_mode_exec_dir =
safe_mode_allowed_env_vars = PHP_
safe_mode_protected_env_vars = LD_LIBRARY_PATH
disable_functions =
highlight.string  = #CC0000
highlight.comment = #FF9900
highlight.keyword = #006600
highlight.bg      = #FFFFFF
highlight.default = #0000CC
highlight.html    = #000000
expose_php = On
max_execution_time = 30     ; Maximum execution time of each script, in seconds
memory_limit = 8M      ; Maximum amount of memory a script may consume (8MB)
error_reporting  =  E_ALL
display_errors = Off
display_startup_errors = Off
log_errors = On
track_errors = Off
warn_plus_overloading = Off
variables_order = "GPCS"
register_globals = Off
register_argc_argv = Off
post_max_size = 8M
pc_order = "GPC"
magic_quotes_gpc = Off
magic_quotes_runtime = Off    
magic_quotes_sybase = Off
auto_prepend_file =
auto_append_file =
default_mimetype = "text/html"
doc_root =
user_dir =
extension_dir = ./
enable_dl = On
file_uploads = On
upload_max_filesize = 2M
allow_url_fopen = On
[... unimportant module-config follows ...]
=================[php.ini]==================

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-06-18 19:57 UTC] sniper@php.net
In another report Markus said this was a documentation problem..reclassified.

 [2004-07-26 17:55 UTC] vrana@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon May 20 22:01:31 2024 UTC