php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #5152 Object passed in a session generates errors when member functions are called
Submitted: 2000-06-20 18:56 UTC Modified: 2000-06-20 19:06 UTC
From: jordan at eblox dot com Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 4.0 Latest CVS (20/06/2000) OS: Linux 2.2.14
Private report: No CVE-ID: None
 [2000-06-20 18:56 UTC] jordan at eblox dot com
I've put three short pages that cause this problem for php 4.0.0. Seems that when an instance of a class is put into a session it becomes unable to access member functions of that instance (not the class, just that instance, as these scripts show), but it can still see variables.

-------------classdec.php----------
<?
// class declaration

class TestClass {
	var $a; 

	function heh($str) {
		echo $str . "<br>";
	}
}

?>
----------index.php----------
<?
session_register("sessionvar");
Include("classdec.php");

// creating an instance of a class to pass as a session var to page.php
$sessionvar = new TestClass;
$sessionvar->a = "someval";

echo "<a href=page.php>link</a>";

?>
----------page.php-----------
<?
session_register("sessionvar");
Include("classdec.php");

$anothervar = new TestClass;

// I can use the variables of this instance that was created on index.php and put in a session
echo $sessionvar->a . "<br>";
// I can call this function on another instance of the same class that I created on this page
$anothervar->heh("this is output from the same function that generates an error on the next line");
// .....crash telling me it's an undefined function.
$sessionvar->heh("rhewswh");
?>
=======================================================
produces following output on page.php after following the link from index.php:

someval
this is output from the same function that generates an error on the next line

Fatal error: Call to undefined function: heh() in <path>/page.php on line 12

==============
any comments would be appreciated.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-06-20 19:06 UTC] stas at cvs dot php dot net
Use "require" or start session after you class got defined.
PHP should know about class to restore it correctly.
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Mon Jun 15 22:00:02 2026 UTC