Re: Herencia de clases y métodos

From: Date: Fri, 12 Apr 2002 15:45:05 +0000
Subject: Re: Herencia de clases y métodos
References: 1 2  Groups: php.general.es 
Request: Send a blank email to general-es+get-21387@lists.php.net to get a copy of this message
Pues no lo sabia, es cierto en php.net <?php // base class with member properties and methods class Vegetable { var $edible; var $color; function Vegetable( $edible, $color="green" ) { $this->edible = $edible; $this->color = $color; } function is_edible() { return $this->edible; } function what_color() { return $this->color; } } // end of class Vegetable // extends the base class class Spinach extends Vegetable { var $cooked = false; function Spinach() { //# //# LLAMADA AL CONSTRUCTOR DE LA CLASE PADRE //# $this->Vegetable( true, "green" ); } function cook_it() { $this->cooked = true; } function is_cooked() { return $this->cooked; } } // end of class Spinach ?> ----- Original Message ----- From: "Kike" <kike@bytenet.es> To: "Pablo M. Beca" <pablo_beca@ciudad.com.ar> Cc: "Lista PHP" <lista@phpes.com> Sent: Friday, April 12, 2002 3:53 PM Subject: Re: [PHP-ES] Herencia de clases y métodos > Hola Pablo, > > Thursday, April 11, 2002, 7:57:23 PM, you wrote: > > PMB> Hola amigos... hace rato que no me daba una vuelta por la lista, > PMB> motivos sobran creo... :) > > PMB> Una consulta... Tengo una definición de clase, llamada CLASS_site, > PMB> con un método llamado AutoConfig() > > PMB> class CLASS_site{ > PMB> ... > PMB> ... > > PMB> function AutoConfig(){ > PMB> .... > PMB> .... > PMB> return; > PMB> } > > PMB> ... > PMB> ... > PMB> } > > PMB> Esta clase define las propiedades básicas que necesito para el > PMB> objeto oSite... Pero, a los efectos de "afinar" un poco más > PMB> este ofecto, normalmente creo otra clase a partir de esta, a > PMB> saber: > > PMB> class CLASS_NewSite extends CLASS_site{ > PMB> ... > PMB> ... > PMB> function AutoConfig(){ > PMB> ... > PMB> ... > PMB> return; > PMB> } > PMB> ... > PMB> ... > PMB> } > > PMB> Hasta acá nada raro... el problema surge es que dentro de > PMB> la nueva clase CLASS_NewSite necesito definir el mismo > PMB> método AutoConfig(). Lo que necesito saber es si esta nuevo > PMB> método reemplaza al anterior. Y si es así, cómo hago para > PMB> llamar al viejo AutoConfig. > > PMB> Saludos > > PMB> Pablo Beca > PMB> Santa Fe - Argentina > PMB> +------------------------------------------------+ > PMB> | Vos también podés hacer algo desde "tu lugar"] | > PMB> | + SUMATE por Argentina, ahora que podemos | > PMB> + -----------------------------------------------+ > PMB> | http://porargentina.enlapc.com | > PMB> +------------------------------------------------+ > > > PMB> --------------------------------------------------------------------- > PMB> Archivo On-line: http://www.phpes.com/ > PMB> via news: news://news.phpes.com/ > PMB> Manual PHP en español: http://www.php.net/manual/es/ > PMB> Para dar de baja la suscripción, mande un mensaje a: > PMB> lista-unsubscribe@phpes.com > > Esto aparece en el manual, es un comentario de un usuario: > > > I just went through all sorts of playing around with the PHP object inheritance, and the following is the best way to call an overloaded parent function as far as I can tell: > > class a { > function init() { > echo "A init > "; > } > } > > class b extends a { > function init() { > a::init(); > echo "B init > "; > } > } > > $x = new b; > $x->init(); > > This will output: > A init > B init > > by calling the init() function of a within the init() function of b through the use of a::init() and it seems to work just fine. > > > -- > Saludos, > Kike mailto:kike@bytenet.es > > > --------------------------------------------------------------------- > Archivo On-line: http://www.phpes.com/ > via news: news://news.phpes.com/ > Manual PHP en español: http://www.php.net/manual/es/ > Para dar de baja la suscripción, mande un mensaje a: > lista-unsubscribe@phpes.com >

« previous php.general.es (#21387) next »