Jump to content

PHP Classes


c_pattle

Recommended Posts

If I have defined an instance of a class in one script how do I then use this same instance and the same variable in other scripts?  For example say I have this code in a file called "index.php"

 

include("myclass.class.php");

$myclass = new myClass;

$myclass->$variable = "hello world";

 

However if I then have this code in a file called "page1.php" when I try to access the same variable it is empty. 

 

include("myclass.class.php");

echo($myclass->$variable)

 

How can I use the same instance of this class across all files keep the variable values the same?

 

Thanks for any help. 

Link to comment
https://forums.phpfreaks.com/topic/226865-php-classes/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.