|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2004-10-13 09:22 UTC] derick@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 12:00:01 2025 UTC |
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