I wish to write an entire class to a txt file on the server... My class is as follows.. <?php class userdata { var $username; var $password; } I wish to write this class to a text file. im given to understand that simply using the fwrite() function will not work. Is there any kind of function to write entire class objects to files? Plz help. Thanks!
In the class itself, create a function called writeout or whatever and pass it the parameters of the file you want. public function writeout($outfile){ // format parameters however fwrite($parameters,$outfile,w); } Then in the code, use Object.writeout($filename).
You'll have to of course figure out how you want the object contents written out. Plaintext, csv, etc.
I'm not sure what your purpose is, but you can serialize objects in PHP. See: http://www.devshed.com/c/a/PHP/The-Basics-of-Serializing-Objects-in-PHP/
<?php class userdata { var $username; var $password; } $u =new userdata; #saving file_put_contents('data.txt', serialize($u)); #reading back and formign same type $u2 = unserialize(file_get_contents('data.txt')); Code (markup): Hope it helps.