php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #34448 Global variables inside of a method of a class are not initialized
Submitted: 2005-09-09 21:07 UTC Modified: 2005-09-10 17:19 UTC
From: diplex19 at yandex dot ru Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.0.5 OS: Windows
Private report: No CVE-ID: None
 [2005-09-09 21:07 UTC] diplex19 at yandex dot ru
Description:
------------
Global variables inside of a method of a class are not initialized

Reproduce code:
---------------
<?
  class test1
  {
     var $my_var;
     function init($str)    { $this->my_var=$str; return $this->my_var; }
  }
  class bug_test
  {
     function set_var($str) { global $info; $info=&new test1(); return $info->init($str); }
     function get_var()     { global $info; return $info->my_var; }
  }
  global $info; 
  $t=&new bug_test();
  $f0=$t->set_var('menu1');
  $f1=$t->get_var();
  $f2=$t->set_var('menu2');
  $f3=$t->get_var();
  echo "f0=$f0\nf1=$f1\nf2=$f2\nf3=$f3\n";  // php-bug! f1<>'menu1' & f3<>'menu2
?>

Expected result:
----------------
f0=menu1
f1=menu1
f2=menu2
f3=menu2

Actual result:
--------------
f0=menu1
f1=
f2=menu2
f3=

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-09-10 17:19 UTC] derick@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

Your code is broken too...
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Dec 23 21:00:01 2025 UTC