ID:               17959
 Updated by:       [EMAIL PROTECTED]
 Reported By:      [EMAIL PROTECTED]
-Status:           Open
+Status:           Analyzed
 Bug Type:         Scripting Engine problem
 Operating System: linux
 PHP Version:      4.2.1
 New Comment:

Related to bug #20993(http://bugs.php.net/20993)



Previous Comments:
------------------------------------------------------------------------

[2002-12-19 12:12:56] [EMAIL PROTECTED]

I grabbed Apache/1.3.27 built and installed it.

Next I grabbed php4-STABLE-200212182230 built and
installed it.

The same test-case presented in this bug report failed.

I also grabbed php4-200212191630 a few minutes ago
built and installed it.

Again, the very same test-case in this bug report failed.

--patrick

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

[2002-12-07 01:46:07] [EMAIL PROTECTED]

Please try using this CVS snapshot:

  http://snaps.php.net/php4-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php4-win32-latest.zip

Could you confirm that the problem still exists in latest CVS and if it
does ,please provide a SMALL (10 or so) line script that could be used
to replicate the problem.

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

[2002-11-27 22:57:56] [EMAIL PROTECTED]

I have experienced similar problems with PHP on Linux 2.4.x.  It only
seems to occur in very weird circumstances where you have a reference
pointing (yes I know references are not pointers) to an array element. 
My only test cases are much larger that those presented by
"[EMAIL PROTECTED]" as they involve production code.  The one piece of
information I can offer which may be of some use is that in my case,
the problem can be eliminated by removing an uneeded "global" statement
(the reference was already in scope).  I realize that sounds absurd,
but I have a case where "global" actually breaks the reference.  When I
comment out the global statement, the reference doesn't get wiped out. 
I know the reference is global because it was created in $GLOBALS.  I
know this seems strange, but I can var_dump it before and after and the
only thing that changes is me commenting out the global statement.

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

[2002-07-29 06:50:20] [EMAIL PROTECTED]

<?php
// Dear Php developer,
//
// After considering your explanation of what exactly 'global $ptr'
// is i changed my code to strictly use $GLOBALS['ptr'].  However,
// after doing so my program still didn't function properly!
//
// I had to work a bit harder to come up with a simplified example
// for you.  I believe i have done so below.
//
// Please pay close attention to the notes w/in comments explaining
// strange conditions that would make this sample code to work as
// expected.  Now I'm certain there EXISTS a serious problem with
// the Php engine when processing this code.
//
// Thanks,
// --patrick

// define array we plan to navigate.
$top =
array
  (
  'name' => 'top',
  'A' => array
          (
          'name' => 'A',
          'A_a' => array
                    (
                    'name' => 'A_a',
                    'fn_1' => 'Aa_fn_1',
                    'fn_2' => 'Aa_fn_2',
                    'fn_3' => 'Aa_fn_3',
                    'A_a_1' => array
                                (
                                'name' => 'A_a_1',
                                'fn_1' => 'Aa1_fn_1',
                                'fn_2' => 'Aa1_fn_2',
                                ),
                    'A_a_2' => array
                                (
                                'name' => 'A_a_2',
                                'fn_1' => 'Aa2_fn_1',
                                'fn_2' => 'Aa2_fn_2',
                                ),
                    ),
          ),
  );

// setup "parent references" for each of the nodes.
$top['parent']              = null;
$top['A']['parent']         = &$top;
$top['A']['A_a']['parent']  = &$top['A'];
$top['A']['A_a']['A_a_1']['parent']  = &$top['A']['A_a'];
$top['A']['A_a']['A_a_2']['parent']  = &$top['A']['A_a'];
//$top['A']['A_a']['A_a_1']['parent']  = &$top['A']['A_a'];
  //
  // Note!
  // Here if we uncomment the above line the sample code will
  // magically WORK!
  //
  // Why does the order of initialization matter!?  And will the
  // code now break elsewhere?

// setup our reference to $top.  $ptr is what should change
// on every call to change_ptr(name).
$ptr  = &$top;

// change_ptr( name ) does the following w/some verbose
// messages to display the state of variables in question.
//
//    if ( ptr[name] )
//      ptr = ptr[name];
//
function change_ptr( $name )
{
  printf( "  change_ptr($name) " );

  if ( $GLOBALS['ptr'][$name] ) {
    // Setting up string for later printing.
    $before_change =
    sprintf( "before: \$GLOBALS['ptr']['name'] = %s",
                       $GLOBALS['ptr']['name'] );

    $GLOBALS['ptr'] = &$GLOBALS['ptr'][$name];

    $after_change =
    sprintf( "after: \$GLOBALS['ptr']['name'] = %s",
                      $GLOBALS['ptr']['name'] );

    printf( "<font color=\"green\"><b>CHANGED</b></font>:\n" );
    printf( "    %s\n     %s", $before_change, $after_change );
  }
  else
    printf( "<font color=\"red\"><b>NO CHANGE!</b></font>" );
    
  printf( "<br>\n" );
}
?>
<pre>
<?
// All of the following calls should succeed and print
// 'CHANGED'.  However, you will notice that the last call
// will fail to change $ptr to point to the 'parent' of
// $top['A']['A_a']['A_a_2'].
//
change_ptr('A');
change_ptr('A_a');
change_ptr('A_a_1');
change_ptr('parent');
change_ptr('A_a_2');
change_ptr('parent');
?>
</pre>

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

[2002-07-23 16:24:54] [EMAIL PROTECTED]

think of the "global $p;" construct as a shortcut for
"$p = &$GLOBALS['p'];" 

so by assigning a new reference you are breaking the one to the global
variable

so you have to explicitly assign to $GLOBALS["p"] here

(marked as documentation problem)

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

The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
    http://bugs.php.net/17959

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

Reply via email to