[PHP] Help with classes (oop)

2003-02-03 Thread Leonard Burton
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

Re: [PHP] Help with classes (oop)

2003-02-03 Thread Chris Hayes
Apparently it does not like the function name to be the same as the class name. So change one of them. ? php; class first { var $age; var $name; function first($age, $name) { return $age.$name; } } //main script $first = new first;

Re: [PHP] Help with classes (oop)

2003-02-03 Thread Chris Boget
Apparently it does not like the function name to be the same as the class name. So change one of them. No, what's happening is that when you instantiate an class, it runs (as a constructor) the function whose name is the same as the class. So when you do this: $first = new first; it's

Re: [PHP] Help with classes (oop)

2003-02-03 Thread Tim Ward
: Chris Hayes [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Monday, February 03, 2003 7:35 PM Subject: Re: [PHP] Help with classes (oop) Apparently it does not like the function name to be the same as the class name. So change one of them. ? php; class first { var $age; var

[PHP] Re:[PHP] Help with classes (oop)

2003-02-03 Thread Daniel Leighton
Hi Leonard, Try this: ? php; class first { var $total; function first($age, $name) { $this-total = $age.$name; } } //main script $obj = new first(35, chris); print $obj-total; ? The problem with what you were doing is that when you

Re: [PHP] Help with classes (oop)

2003-02-03 Thread Johannes Schlueter
On Monday 03 February 2003 20:45, Chris Boget wrote: function setData( $age, $name ) { $age = $age; $name = $name; } Is useless ;-) I think you wanted this: function setData( $age, $name ) { $this-age = $age;

Re: [PHP] Help with classes (oop)

2003-02-03 Thread Chris Boget
function setData( $age, $name ) { $age = $age; $name = $name; } Is useless ;-) I think you wanted this: function setData( $age, $name ) { $this-age = $age; $this-name = $name; } Good

RE: [PHP] Help with classes (oop)

2003-02-03 Thread Leonard Burton
; return $retval; } } -Original Message- From: Johannes Schlueter [mailto:[EMAIL PROTECTED]] Sent: Monday, February 03, 2003 2:59 PM To: [EMAIL PROTECTED] Subject: Re: [PHP] Help with classes (oop) On Monday 03 February 2003 20:45, Chris Boget wrote: function setData

Re: [PHP] Help with classes (oop)

2003-02-03 Thread Maxim Maletsky
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