note 86894 added to language.oop
| From: | mozo_grand at yahoo dot com | Date: | Sun, 09 Nov 2008 13:38:19 +0000 |
| Subject: | note 86894 added to language.oop | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-146314@lists.php.net to get a copy of this message | ||
Stated above by 'buzz77 at gmx dot net' assigning classes to session variables appears to
be incorrect.
Using php v5.05 it does not work, i suspect the user had register_globals set to on giving incorrect
results.
My test code was as follows
Created a library file for the class
<?php
// class-test-lib.php
class simple {
function dummy() {
print "TEST SUCCESSFUL !";
}
}
?>
created a test php file
<?php
require("class-test-lib.php");
session_start();
?>
<html>
<head>
<title>Class Test Page 1</title>
</head>
<body>
<?php
session_register("testVar");
$testVar=new simple();
$testVar->dummy();
?>
<br />
<a href="class-test2.php">Second Page</a>
</body>
</html>
Outputs correctly the message from the class
created the second page test php file
<?php
require("class-test-lib.php");
session_start();
?>
html>
<head>
<title>Class Test Page 2</title>
</head>
<body>
<?php
$testVar->dummy();
?>
</body>
</html>
results in the following error:
Notice: Undefined variable: testVar in c:\Inetpub\wwwroot\class-test2.php on line 14
Fatal error: Call to a member function dummy() on a non-object in c:\Inetpub\wwwroot\class-test2.php
on line 14
It appears that the session registration is not effective and the original posters results are more
likely due to having globals on.
I have not found a solution to this problem.
----
Server IP: 69.147.83.197
Probable Submitter: 84.68.31.22
----
Manual Page -- http://www.php.net/manual/en/language.oop.php
Edit -- https://master.php.net/note/edit/86894
Del: integrated -- https://master.php.net/note/delete/86894/integrated
Del: useless -- https://master.php.net/note/delete/86894/useless
Del: bad code -- https://master.php.net/note/delete/86894/bad+code
Del: spam -- https://master.php.net/note/delete/86894/spam
Del: non-english -- https://master.php.net/note/delete/86894/non-english
Del: in docs -- https://master.php.net/note/delete/86894/in+docs
Del: other reasons-- https://master.php.net/note/delete/86894
Reject -- https://master.php.net/note/reject/86894
Search -- https://master.php.net/manage/user-notes.php