Edit report at https://bugs.php.net/bug.php?id=63714&edit=1

 ID:                 63714
 User updated by:    axdr at bk dot ru
 Reported by:        axdr at bk dot ru
 Summary:            incorrect global statement
 Status:             Not a bug
 Type:               Bug
 Package:            Scripting Engine problem
 Operating System:   Windows
 PHP Version:        5.4.9
 Block user comment: N
 Private report:     N

 New Comment:

Sorry. You are right.
But I think this is irrational. 
It's impossible to read all documentation and to remember word for word.
This is a kind of underwater mine.


Previous Comments:
------------------------------------------------------------------------
[2012-12-07 02:54:35] larue...@php.net

also see:

<?php
function func() {
    global $a, $b;
    $a = 'aaa'; 
    $b = &$a;
    $b = 'bbb';
}   
    
func();
var_dump($a);

output:
bbb

------------------------------------------------------------------------
[2012-12-07 02:52:22] larue...@php.net

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

global $a;
  make a local variable 'a' reference to $GLOBALS['a'];

also thinking of:

$b = &$a;  // b reference to a
$b = &$c;  // change reference to c


then:
  global $a, $b;   //b reference to $GLOBALS['b']
  $a = 'aaa';
  $b = &$a;        //b now reference to local $a with GLOBALS['b'] unchanged

------------------------------------------------------------------------
[2012-12-07 02:44:58] axdr at bk dot ru

'global'-declaration kills referencies

  function func() {
    global $a, $b;
    $a = 'aaa';
    $b = &$a;
    echo "$a, $b", '<br>';
    global $a, $b;
    echo "$a, $b";
  }
  func();

output: 
  aaa, aaa
  aaa,

------------------------------------------------------------------------
[2012-12-07 02:37:38] axdr at bk dot ru

Description:
------------
'global'-declaration inside a function dosn't affect referencies.

Test script:
---------------
function func() {
    global $a, $b;
    $a = 'aaa';
    $b = &$a;
    $GLOBALS['c'] = &$a;
}
func();
echo "$a, $b, $c"; 



Expected result:
----------------
aaa, aaa, aaa

Actual result:
--------------
aaa, , aaa



------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=63714&edit=1

Reply via email to