CodeIgniter Forums
[SOLVED] Creating libraries - can PHP 4 class properties retain their value between function calls? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: [SOLVED] Creating libraries - can PHP 4 class properties retain their value between function calls? (/showthread.php?tid=12936)



[SOLVED] Creating libraries - can PHP 4 class properties retain their value between function calls? - El Forum - 11-05-2008

[eluser]MMacdonald[/eluser]
I'm creating my own library. Even though I run PHP 5, I'm coding to PHP 4 to keep it reusable. The gist of my problem is shown in the following pseudo-code - specifically, how do I get PHP 4 to make $property retain its value between function calls?

Code:
class library_example {

var $property="";

function write($value)
  {
   $this->property=$value;
  }

function read()
  {  
   return $this->property;
  }

}



[SOLVED] Creating libraries - can PHP 4 class properties retain their value between function calls? - El Forum - 11-05-2008

[eluser]MMacdonald[/eluser]
I've solved this myself - the code does behave exactly as expected - I'd forgotten that I next time the page loads, it's a new instance of the class.


[SOLVED] Creating libraries - can PHP 4 class properties retain their value between function calls? - El Forum - 11-05-2008

[eluser]Colin Williams[/eluser]
Yerp.. Stateless is the way to think