Re: Class and subclass

From: Date: Tue, 13 Mar 2007 17:14:41 +0000
Subject: Re: Class and subclass
References: 1 2 3 4 5 6 7  Groups: php.general 
Request: Send a blank email to php-general+get-250471@lists.php.net to get a copy of this message
Alain Roger wrote:
Hi Richard, In fact the problem is that under Zend Studio editor, when i typed : $this->class_A_property->Class_B_method did not appear as valid. if i typed $this->class_A_property , this was valid because $this refered to Class_A. but if you define a property (private $myobject_B) in class A, and create an instance via $this->myobject_B = new Class_B(); after : $this->myobject_B->Class_B_method was displayed as not correct syntax in Zend :-( You are remembering to call it with parenthesis @ the end
Otherwise it would be seen as a property instead of a method call. Just a thought so, you have something that looks like this??? <?php class Class_A { function __construct() { $this->myobject_B = new Class_B(); //This should work $this->myobject_B->Class_B_method(); //this should fail $this->myobject_B->Class_B_method; } function Class_A() { return $this->__construct(); } } class Class_B { function __contruct() { } function Class_B() { return $this->__contruct(); } function Class_B_method() { echo 'Class_B_method was called'; } } $obj = new Class_A(); ?> This is my results: Class_B_method was called Notice: Undefined property: Class_B::$Class_B_method in class_test.php on line 9
Al. On 3/13/07, Richard Lynch <ceo@l-i-e.com> wrote:
I think he's claiming that if you typed it correctly, it should work. You haven't told us anything about the "not working" part... var_dump $this->myotherclass and see what's in it. On Wed, March 7, 2007 8:45 am, Alain Roger wrote:
Yes, for sure. On 3/7/07, Tijnema ! <tijnema@gmail.com> wrote:
On 3/7/07, Alain Roger <raf.news@gmail.com> wrote:
A() or B() mean constructors of th class A and B respectively. Al.
Yes but they are functions. On 3/7/07, Robert Cummings <robert@interjinn.com> wrote:
On Wed, 2007-03-07 at 14:23 +0100, Alain Roger wrote:
Hi, i have a class A with some properties. i have a class B with several public functions (i.e : Render()) i would like to do something like that : class B() { B()
I'm pretty sure you mean "function B()" or in PHP 5 "function __construct()".
{ } public function Render() { ... } } class A { private $myotherclass; A()
Similarly, I'm pretty sure you mean "function A()" or in PHP 5
"function
__construct()".
{ $this->myotherclass = new classB(); } public function test() { $this->myotherclass->Render(); } } however, i'm not able to access to ->Render() of class B from Class
A
property. Where could be the problem ?
Cheers, Rob. -- .------------------------------------------------------------. | InterJinn Application Framework - http://www.interjinn.com | :------------------------------------------------------------: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for       |
| creating re-usable components quickly and easily.          |
`------------------------------------------------------------'
-- Alain ------------------------------------ Windows XP SP2 PostgreSQL 8.1.4 Apache 2.0.58 PHP 5
-- Alain ------------------------------------ Windows XP SP2 PostgreSQL 8.1.4 Apache 2.0.58 PHP 5
-- Some people have a "gift" link here. Know what I want? I want you to buy a CD from some starving artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So?
-- Enjoy, Jim Lucas Different eyes see different things. Different hearts beat on different strings. But there are times for you and me when all such things agree. - Rush

« previous php.general (#250471) next »