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 crea

RE: [PHP] Help with classes (oop)

2003-02-03 Thread Leonard Burton
his->age; $retval .= $this->name; 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 2

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; >

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;

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

2003-02-03 Thread Daniel Leighton
Hi Leonard, Try 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 were instantiating the class, with the way you have set this up, you need to pass arguments because when you create

Re: [PHP] Help with classes (oop)

2003-02-03 Thread Tim Ward
- From: 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. > > > &

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 auto

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. first(35, "chris"); print $test; ?> -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php

[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

2001-02-13 Thread Jesse Swensen
on 2/13/01 12:04 AM, Joe Conway at [EMAIL PROTECTED] wrote: > > class Foo { > > var $bar; > > function mymethod(){ > > global $foo; > $this->bar = $foo; > > } > > } > > $foo = "hello world"; > > echo ""; > > $cls = new foo(); > $cls->mymethod(); > echo $cls->bar; > > echo ""; > ?> Thi

Re: [PHP] help with classes

2001-02-13 Thread Marcus Rasmussen
You can allso do this: //foo.class.php class Foo{ var $bar; function Foo($bar){ $this->bar = $bar; } } //foo.php include("foo.class.php"); $bar = "1234"; $foo = new Foo($bar); //Now: $foo->bar = "1234" Regards: Marcus Rasmussen *** REPLY SEPARAT

Re: [PHP] help with classes

2001-02-12 Thread Ankur Verma
uot;php-general" <[EMAIL PROTECTED]> Sent: Wednesday, February 14, 2001 9:27 AM Subject: [PHP] help with classes > hey all, > > Was just wondering how to do the following: > > class Foo { > > var $bar = $foo; // causes parse error > var $bar = "$foo"

Re: [PHP] help with classes

2001-02-12 Thread Joseph H Blythe
On Mon, 12 Feb 2001 21:04:30 -0800 Joe wrote: JC> Is this closer to what you were looking for? JC> - Joe JC> JC> JC> class Foo { JC> JC> var $bar; JC> JC> function mymethod(){ JC> JC> global $foo; JC> $this->bar = $foo; JC> JC> } JC> JC> } JC> JC> $foo = "hello world"; JC> JC> e

Re: [PHP] help with classes

2001-02-12 Thread Joe Conway
> SC> > SC> That's how you have to do it. > SC> > SC> > SC> class MyClass { > SC> var $bar; > SC> > SC> // This is the class's constructor > SC> sub MyClass () { > SC> $this->bar = $foo; > SC> } > SC> } > > I didn't think php had sub routines like perl? shouldn't that be: > > function MyClass(){ >

Re: [PHP] help with classes

2001-02-12 Thread Joseph H Blythe
On Mon, 12 Feb 2001 23:44:08 -0500 (EST) Sean wrote: SC> SC> That's how you have to do it. SC> SC> SC> class MyClass { SC> var $bar; SC> SC> // This is the class's constructor SC> sub MyClass () { SC> $this->bar = $foo; SC> } SC> } I didn't think php had sub routi

Re: [PHP] help with classes

2001-02-12 Thread Sean Cazzell
> So how does one correctly assign a variable to a variable inside a class withot >doing something like: > > var $bar = ''; > $this->bar = $foo; > That's how you have to do it. class MyClass { var $bar; // This is the class's constructor sub MyClass () {

Re: [PHP] help with classes

2001-02-12 Thread Joseph H Blythe
On Mon, 12 Feb 2001 20:11:14 -0800 Joe wrote: JC> JC> I was curious too, so I looked it up. Seems you can't. From JC> http://www.php.net/manual/en/language.oop.php JC> JC> "Note: In PHP 4, only constant initializers for var variables are JC> allowed. Use constructors for non-constant initia

Re: [PHP] help with classes

2001-02-12 Thread Joe Conway
> Was just wondering how to do the following: > > class Foo { > > var $bar = $foo; // causes parse error > var $bar = "$foo"; // causes parse error > var $bar = '$foo'; // works but $foo is not evaluated > > } > ?> > > So how does one correctly assign a variable to a variable inside a class witho

[PHP] help with classes

2001-02-12 Thread Joseph H Blythe
hey all, Was just wondering how to do the following: So how does one correctly assign a variable to a variable inside a class withot doing something like: var $bar = ''; $this->bar = $foo; Any insight would be much appreciated. Regards Joseph -- PHP General Mailing List (http://www.php.