|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2000-11-09 05:23 UTC] hholzgra@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 23:00:01 2025 UTC |
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