Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
|
Dan, 2 things...
First:
Use php5 declaration, if you can.
You can use the keywords "public", "private" and "protected".
The php4 declaration, like you used, default to "public" in php5.
Public means that the property/function is accessible from the outside of the object.
Private means the property/function is accessible only in the object.
Protected means that the property/function is accessible only from the object or from an object who's extended the parent object.
PHP Code:
class clTest{ public $title; private $content;
public function __construct($title,$content){ $this->title=$title; $this->content=$content; } }
and in PHP4:
PHP Code:
class clTest{ var $title; var $content;
function clTest($title,$content){ $this->title=$title; $this->content=$content; } }
the __construct function is the constructor in PHP5. In PHP4, it's a function that have the same name as the class. in this case, it would be a function clTest($title,$content);
Second:
When the constructor have parameters, you can get them when you create an object of your class
PHP Code:
var $obj=new clTest('This is the title','This is the content');
__________________
Only a biker knows why a dog sticks his head out the window.
Last edited by tripy; 03-06-2008 at 11:58 AM..
|