Re: Is posible to call a class method from anoter class?

From: Date: Mon, 16 Oct 2000 20:05:12 +0000
Subject: Re: Is posible to call a class method from anoter class?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-20447@lists.php.net to get a copy of this message
Eduardo Jordán G. writes: > Hello, > > I would like to know if is posible to call a > class method from another diferent class. Also > want to proper method to access data from another > class. Yes, just do it like any class: $a = new A; $a->foo(); It doesn't change inside of other classes, except for the fact that 'inside' a class, you're always inside a function, so if the one object exists in the global scope, you'll need to globalize it like any other variable. There is lots of information on how to use classes and object in the manual: http://www.php.net/manual/language.oop.php > class A > { > var $array; > > function foo() > { > } > } > > class B > { > var $data1; > > function B > { > foo(); // this is foo defined within class A Should be $a->foo(), assuming that you've instantiated class A to $a. > echo $array; //this is also defined within class A This would be $a->array; > } > } > > Please response direct to my e-mail since I subscribed to php-general-digest > list only. > > Thank you!!! -- +----------------------------------------------------------------+ |Torben Wilson <torben@php.net> Netmill iTech| |http://www.coastnet.com/~torben http://www.netmill.fi| |Ph: 1 250 383-9735 torben@netmill.fi| +----------------------------------------------------------------+

« previous php.general (#20447) next »