View Single Post
Old 05-08-2005, 01:21 AM   #3 (permalink)
zeromancer
The Wanderer
Newcomer 
 
Join Date: May 2005
Posts: 5
Thanks: 0
zeromancer is on a distinguished road
Default

OOP was completely redesigned in PHP 5. I would suggest upgrading to the most current version so you don't have to completely relearn everything when you move to PHP 5. The object structures were redesigned to have a much more java feel to them, complete with contructors and destructors, autoload, and much more predicatable behavior. but a VERY short tutorial follows for php 5:
PHP Code:
//class file
class myClass {
  
__constructor myCLass() {  //a constructor is executed when the class is initialized.
    
$this->name "default name";
  }

  function 
setName($newName) {
    
$this->name $newName;  //$this is a variable that should be used
  
}                           // when calling functions or variables from
                                         // within the class itself.
  
function getName() {
    return 
$this->name;
  }

  
__destructor killClass() {
    echo 
"Class is being destroyed.";
  }
}

//Inside your script

include("myClass.php");
$nameClass = new myClass(); //Initializes your new class.

echo $nameClass->getName(); // echos "Default Name"

$nameClass->setName("Steve");  //changes the name inside the class

echo $nameClass->getName();  // echos "Steve"

$nameClass->killClass();  //removes the class object from memory. 
I should be around to help if you have any other questions. I'm in the process of learning the new PHP5 oop structure myself. luckily i have a pretty good book on the subject.
Send a message via AIM to zeromancer
zeromancer is offline  
Reply With Quote