note 60543 added to function.include

From: Date: Tue, 10 Jan 2006 19:31:56 +0000
Subject: note 60543 added to function.include
Groups: php.notes 
Request: Send a blank email to php-notes+get-101509@lists.php.net to get a copy of this message
When you include a page in a function, this page will have local scope, so you will need the 'global' keyword to use a variable from the global scope or to set a variable that the can be used in the global scope. Example: <?php //file.php (include file) //Using a var from the global scope global $a; echo $a; //Setting a var at the local scope include so that it can be used at the global scope global $b; $b = 'include var'; ?> <?php //main page $a = 'global var'; function doSomething() { //some code include('file.php'); } doSomething(); //Using a var from the local scope include echo $b; ?> ---- Manual Page -- http://www.php.net/manual/en/function.include.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+60543 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+60543&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+60543&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+60543&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+60543&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+60543&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+60543&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+60543&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+60543&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#101509) next »