Re: Help with classes (oop)

From: Date: Tue, 04 Feb 2003 01:38:55 +0000
Subject: Re: Help with classes (oop)
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-134200@lists.php.net to get a copy of this message
When you name a function in the class with the same name as the class itself, this function gets automatically executed upon defining the object (class). this is called `constructor'. in your very case, this is the function first, which requires two parameters to be passed to it. You need to create the instance (define) your class with already passing parameters to it. Like this: $obj = new First($par1, $par2); The next, you don't need to call $obj->first(..., ...); once again, as you just did it one line above. -- Maxim Maletsky maxim@php.net On Mon, 3 Feb 2003 14:27:36 -0500 "Leonard Burton" <lbburt0@pop.uky.edu> wrote: > Greetings, > > I am trying to figure out using classes. I have read and read and read > about them but still cannot figure them new fangled things out. Could > someone please alter this snippet just a bit so it would be a correct test > script with a call to it? > > When I run the script I get this in my browser << > > Warning: Missing argument 1 for first() in /usr/~~~~~~~~~~~~~index.php on > line 8 > Warning: Missing argument 2 for first() in /usr/~~~~~~~~~~~~~~~~~/index.php > on line 8 > 35chris > >> > > As you see it does print the output. What am I doing wrong? > > Thanks, > > Leonard > lbburt0@pop.uky.edu > > > > <? php; > class first > { > var $age; > var $name; > > function first($age, $name) > { > return $age.$name; > } > } > > //main script > $first = new first; > $test=$first->first(35, "chris"); > > print $test; > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php >

« previous php.general (#134200) next »