PHP 4.0 Bug #7717 Updated: No access to server & session variables from within a class
| From: | hholzgra@php.net | Date: | Thu, 09 Nov 2000 10:23:39 +0000 |
| Subject: | PHP 4.0 Bug #7717 Updated: No access to server & session variables from within a class | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-37516@lists.php.net to get a copy of this message | ||
ID: 7717
Updated by: hholzgra
Reported By: p_vruggink@wish.net
Status: Closed
Bug Type: Class/Object related
Assigned To:
Comments:
as usual you have to use 'global $variable;' to get access
to a global variable from within a function or a class method
or use the special GLOBALS array: $GLOBALS['variable']
PHP functions do _not_ inherit the global namespace by default
Previous Comments:
---------------------------------------------------------------------------
[2000-11-09 05:08:25] p_vruggink@wish.net
You can't access servervariables (e.g. $DOCUMENT_ROOT, $SERVER_NAME) or access sessionvariables
directly from within a class, although you can start/stop a session within a class. Is there a class
environment in PHP?
testscripts
MyRoot.php:
<?php
class MyRoot
{
function getMyRoot()
{
return $DOCUMENT_ROOT;
}
}
?>
MySession.php
<?php
class MySession
{
function setMySession()
{
if(session_register("myVar"))
{
$myVar = "Test";
return true;
}
else return false;
}
}
?>
Test.php
<?php
include("MyRoot.php");
include("MySession.php");
$root = new MyRoot();
$sess = new MySession();
if( $sess -> setMySession())
{
print "<HTML><BODY>";
print "Session has been initiated (id: " . session_id() . ")<BR>";
print "session_is_registered ("myVar"): ";
print session_is_registered ("myVar") ? " yes": " no";
print "<BR>";
print "DocumentRoot: " . $root -> getMyRoot() . "<BR>";
print "SessionVarValue: " . $myVar;
print "</BODY></HTML>";
}
?>
Regards and thanks for PHP!
Peter
---------------------------------------------------------------------------
Full Bug description available at: http://bugs.php.net/?id=7717