|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #7717 No access to server & session variables from within a class
Submitted: 2000-11-09 05:08 UTC Modified: 2000-11-09 05:23 UTC
From: p_vruggink at wish dot net Assigned:
Status: Closed Package: Class/Object related
PHP Version: 4.0.2 OS: win98/2000, Apache 1.3.12
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: p_vruggink at wish dot net
New email:
PHP Version: OS:


 [2000-11-09 05:08 UTC] p_vruggink at wish dot 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?

class MyRoot
  function getMyRoot()
    return $DOCUMENT_ROOT;
class MySession
  function setMySession()
      $myVar = "Test";
      return true;
    else return false;

  $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!



Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2000-11-09 05:23 UTC]
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
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Jul 15 08:01:28 2024 UTC