How to get the child name from within the parent?

This is a discussion on How to get the child name from within the parent? within the PHP General forums, part of the PHP Programming Forums category; Hello there, Is there a way to get the child class name from within the parent method? If so, how? ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 09-10-2007
Mathijs
 
Posts: n/a
Default How to get the child name from within the parent?

Hello there,

Is there a way to get the child class name from within the parent method?

If so, how?

Thx in advance.

Example:

class MyParent {
public static function start() {
// Do something like this???
return get_child_name(); // returns 'MyChild' in this case
}
}

class MyChild extends MyParent {
public static childStart() {
// Should return the child class name.
echo parent::start();
}
}
Reply With Quote
  #2 (permalink)  
Old 09-10-2007
Robert.Degen@rwth-aachen.de
 
Posts: n/a
Default Re: [PHP] How to get the child name from within the parent?


----- Ursprüngliche Nachricht -----
Von: Mathijs <mathijs.van.veluw@smscity.com>
Datum: Montag, September 10, 2007 3:19 pm
Betreff: [php] How to get the child name from within the parent?
An: php-general@lists.php.net

> Hello there,
>
> Is there a way to get the child class name from within the parent
> method?


Yes.

> If so, how?


1) If you abandon static'ness, you can use 'get_class($this)'within parent class' func.
2) Fizzle around with some 'self' as pass over argument.
3) or else.....

But - I can't recognize any exigence. Could you describe *what* you wanna do so you must use this?

>
> Thx in advance.
>
> Example:
>
> class MyParent {
> public static function start() {
> // Do something like this???


> return get_child_name(); // returns 'MyChild' in this case


I don't know this function. I couldn't even find it at php doc.
WHAT is that ?

> }
> }
>
> class MyChild extends MyParent {


> public static childStart() {


public static function childStart() {

> // Should return the child class name.
> echo parent::start();
> }
> }
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>


So far.

Rob
Reply With Quote
  #3 (permalink)  
Old 09-10-2007
Mathijs
 
Posts: n/a
Default Re: [PHP] How to get the child name from within the parent?

Robert.Degen@rwth-aachen.de wrote:
> ----- Ursprüngliche Nachricht -----
> Von: Mathijs <mathijs.van.veluw@smscity.com>
> Datum: Montag, September 10, 2007 3:19 pm
> Betreff: [php] How to get the child name from within the parent?
> An: php-general@lists.php.net
>
>> Hello there,
>>
>> Is there a way to get the child class name from within the parent
>> method?

>
> Yes.
>
>> If so, how?

>
> 1) If you abandon static'ness, you can use 'get_class($this)' within parent class' func.
> 2) Fizzle around with some 'self' as pass over argument.
> 3) or else.....
>
> But - I can't recognize any exigence. Could you describe *what* you wanna do so you must use this?
>


I need this because i want to make a default Flow-Control class.
Other classes can extend from this flow class, and pass an array with
the kind of flow they want.

Some of these methods are in the child-class and there for i need its name.

But i didn't checked non-static part yet.
Going to try this.

Thx.


>> Thx in advance.
>>
>> Example:
>>
>> class MyParent {
>> public static function start() {
>> // Do something like this???

>
>> return get_child_name(); // returns 'MyChild' in this case

>
> I don't know this function. I couldn't even find it at php doc.
> WHAT is that ?
>
>> }
>> }
>>
>> class MyChild extends MyParent {

>
>> public static childStart() {

>
> public static function childStart() {
>

Oeps, forgot that.

>> // Should return the child class name.
>> echo parent::start();
>> }
>> }
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>

>
> So far.
>
> Rob

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 06:37 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0