How to add a user to the ignore list?
Why parent::construct not called?
Hello Guest
  
  • Login
• Register…
• Start blog
  • Who, Where, When
• What can I do?
• What to Read?
  • Polls
• Avatars
• Interests
  • Cities and Countries
• Random blog
• Users search
  • Search
• Games
• Tests
• QAIX
  • Сообщества
• Talxy Chat
• Horoscope
• Online
 
Зарегистрируйся!

QAIX > PHP web-programming > Why parent::construct not called? 23 March 2008 01:03:23

  Recent blog posts: 
  They have birthday today: 
  Forums:   
  Discuss: 
  Recent forum topics: 
  Recent forum comments:
  Moderators:

Why parent::construct not called?

Michel 'Ziobudda' Morelli 23 March 2008 01:03:23
 Hi, why if I have

class B extends A {
}

the only way to call in automatic the A::__construct() is to not write
the B::__construct() ?

Ok, this is the design of PHP. But why ?

tnx

--
michel 'ziobudda' morelli <michel@ziobudda.ne­t>


--
PHP Development Mailing List <http://www.php.net­/>
To unsubscribe, visit: http://www.php.net/­unsub.php


Add comment
Marcus BГ¶rger 23 February 2003 19:32:49 permanent link ]
 At 16:46 23.02.2003, michel 'ziobudda' morelli wrote:>Hi, why if I have>
class B extends A {>}>
the only way to call in automatic the A::__construct() is to not write>the B::__construct() ?>
Ok, this is the design of PHP. But why ?

You can do the following:
class base {
function __construct() {
echo "base::__construct(­)\n";
}

function __destruct() {
echo "base::__destruct()­\n";
}
}

class derived extends base {
function __construct() {
parent::__construct­();
echo "derived::__constru­ct()\n";
}

function __destruct() {
parent::__destruct(­);
echo "derived::__destruc­t()\n";
}
}

See:
http://marcus-boerg­er.de/php/ext/ze2/ct­or_dtor_inheritance.­phpt.txt

regards
marcus




--
-------------------­--------------------­--------------------­-----------
Marcus BГ¶rger - Looking for all sorts of freelance work - just ask...

Did i help you? Consider a gift:
http://www.amazon.d­e/exec/obidos/wishli­st/ho722v0rg1u0
-------------------­--------------------­--------------------­-----------


--
PHP Development Mailing List <http://www.php.net­/>
To unsubscribe, visit: http://www.php.net/­unsub.php


Add comment
Michel 'Ziobudda' Morelli 23 February 2003 20:04:20 permanent link ]
 Il dom, 2003-02-23 alle 17:32, Marcus BГ¶rger ha scritto:> You can do the following:> class base {> function __construct() {> echo "base::__construct(­)\n";> }
[...]

I know know.

What I want to understand is why the base::__construct()­ is called (in
automatic) only when derived::__constuct­() is missing.

I think that or the base::__construct()­ is always in automatic called or
it is always never called (in automatic).

bye
--
michel 'ziobudda' morelli <michel@ziobudda.ne­t>


--
PHP Development Mailing List <http://www.php.net­/>
To unsubscribe, visit: http://www.php.net/­unsub.php


Add comment
Marcus BГ¶rger 23 February 2003 20:07:17 permanent link ]
 At 18:02 23.02.2003, michel 'ziobudda' morelli wrote:>Il dom, 2003-02-23 alle 17:32, Marcus BГ¶rger ha scritto:> > You can do the following:> > class derived extends base {> > function __construct() {> > parent::__construct­();> > echo "derived::__constru­ct()\n";> > }> >
I know know.>
What I want to know is why the base::__construct()­ is called (in>automatic) only when derived::__constuct­() is missing.>
I think that or the base::__construct()­ is always in automatic called or>it is never called (always in automatic).


In ZE2 each class has a constructor. That constructor can be overwritten
by writing a method named "__construct". So far so good. Unlike other
languages, C++ for one, PHP does not call any inherited constructors
automatically, C++ calls the default constructor if not set explicitly. But
PHP inherits the constructor if it is not redeclared/overwrit­ten. Therfor
if the base has a constructor and the derived has not the inherited (the
one from base) is called.

regards
marcus



--
-------------------­--------------------­--------------------­-----------
Marcus BГ¶rger - Looking for all sorts of freelance work - just ask...

Did i help you? Consider a gift:
http://www.amazon.d­e/exec/obidos/wishli­st/ho722v0rg1u0
-------------------­--------------------­--------------------­-----------


--
PHP Development Mailing List <http://www.php.net­/>
To unsubscribe, visit: http://www.php.net/­unsub.php


Add comment
Timm Friebe 23 February 2003 20:29:05 permanent link ]
 On Sun, 2003-02-23 at 18:04, michel 'ziobudda' morelli wrote:> Il dom, 2003-02-23 alle 17:32, Marcus BГ¶rger ha scritto:> > You can do the following:> > class base {> > function __construct() {> > echo "base::__construct(­)\n";> > }> [...]>
I know know.>
What I want to understand is why the base::__construct()­ is called (in> automatic) only when derived::__constuct­() is missing.

Because (from a user's point of view) the constructor is inherited just
like any other function.
I think that or the base::__construct()­ is always in automatic called or> it is always never called (in automatic).

Well, because there might be situations in which I'd like to call the
parent's constructor before my code in __construct, sometimes after it
and in some situations, not call it at all.

- Timm


--
PHP Development Mailing List <http://www.php.net­/>
To unsubscribe, visit: http://www.php.net/­unsub.php


Add comment
Michel 'Ziobudda' Morelli 23 February 2003 20:31:30 permanent link ]
 Il dom, 2003-02-23 alle 18:07, Marcus BГ¶rger ha scritto:> In ZE2 each class has a constructor. That constructor can be overwritten> by writing a method named "__construct". So far so good.

Ok...
This is the design..

tnx.

--
michel 'ziobudda' morelli <michel@ziobudda.ne­t>


--
PHP Development Mailing List <http://www.php.net­/>
To unsubscribe, visit: http://www.php.net/­unsub.php


Add comment
Marcus Brger 23 February 2003 20:34:24 permanent link ]
 At 18:29 23.02.2003, Timm Friebe wrote:>Well, because there might be situations in which I'd like to call the>parent's constructor before my code in __construct, sometimes after it>and in some situations, not call it at all.

I hope you will never avoid initialising the base class or just call
the base constructor after anything else is done in the dericed
constructor. The problem is that when you so the behavior of the
base class members (functions and properties) is not predictable.

marcus


--
PHP Development Mailing List <http://www.php.net­/>
To unsubscribe, visit: http://www.php.net/­unsub.php


Add comment
Guest 23 March 2008 01:03:23 permanent link ]
 really stupid design decision of php team
Add comment
 

Add new comment

As:
Login:  Password:  
 
 
  
 
Пожалуйста, относитесь к собеседникам уважительно, не используйте нецензурные слова, не злоупотребляйте заглавными буквами, не публикуйте рекламу и объявления о купле/продаже, а также материалы нарушающие сетевой этикет или УК РФ.


QAIX > PHP web-programming > Why parent::construct not called? 23 March 2008 01:03:23

see also:
[Security & JAAS/JBoss]…
[JBoss jBPM] - Re: Spring is in the air
[JBoss Portal] - Portal bridge for…
пройди тесты:
see also:
10 Reasons to Buy a DSLR Camera
MSOffice 2007
What Grandma knows

  Copyright © 2001—2008 QAIX
Idea: Miсhael Monashev
Помощь и задать вопросы можно в сообществе support.qaix.com.
Сообщения об ошибках оставляем в сообществе bugs.qaix.com.
Предложения и комментарии пишем в сообществе suggest.qaix.com.
Информация для родителей.
Write us at:
If you would like to report an abuse of our service, such as a spam message, please .