#30418 [Opn->Bgs]: can't get values from a class's method when include this class that use global
| From: | derick@php.net | Date: | Wed, 13 Oct 2004 07:22:46 +0000 |
| Subject: | #30418 [Opn->Bgs]: can't get values from a class's method when include this class that use global | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-67520@lists.php.net to get a copy of this message | ||
ID: 30418
Updated by: derick@php.net
Reported By: tonerzhang at hotmail dot com
-Status: Open
+Status: Bogus
Bug Type: Feature/Change Request
Operating System: windows2000 server sp4
PHP Version: 4.3.8
New Comment:
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
No bug here, you include the class inside a function, so the variable
is not put in the global scope but in the the function that called the
include.
Previous Comments:
------------------------------------------------------------------------
[2004-10-13 04:13:44] tonerzhang at hotmail dot com
Description:
------------
Hello,
Excuse my too poor english!
question:
can't get values from a class's method when include this class that use
global variable.
please run the exemple:test1.php and exemple:test2.php
why?
exemple:
test1.php
<?php
function showVar() {
include 'class_test.php';
$obc = new testClass();
$obc->showVar();
}
showVar();
?>
test2.php
<?php
include 'class_test.php';
function showVar() {
$obc = new testClass();
$obc->showVar();
}
showVar();
?>
class_test.php
<?php
$tmpVar = "test data";
class testClass {
function showVar() {
global $tmpVar;
var_dump($tmpVar);
}
}
?>
Reproduce code:
---------------
class_test.php
<?php
$tmpVar = "test data";
class testClass {
function showVar() {
global $tmpVar;
var_dump($tmpVar);
}
}
?>
test1.php
<?php
function showVar() {
include 'class_test.php';
$obc = new testClass();
$obc->showVar();
}
showVar();
?>
Expected result:
----------------
string:"test data"
Actual result:
--------------
NULL
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=30418&edit=1