PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > php.general > How to get the child name from within the parent?
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
How to get the child name from within the parent?

Réponse
 
LinkBack Outils de la discussion
Vieux 10/09/2007, 14h17   #1
Mathijs
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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();
}
}
  Réponse avec citation
Vieux 10/09/2007, 14h47   #2
Robert.Degen@rwth-aachen.de
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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
  Réponse avec citation
Vieux 10/09/2007, 15h00   #3
Mathijs
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 20h49.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,11635 seconds with 11 queries