PHP - Crear un nuevo ejemplo de clase dentro de otra clase

  • yenk
  • Born
  • Born
  • No Avatar
  • Registrado: Oct 30, 2010
  • Mensajes: 1
  • Status: Offline

Nota Octubre 30th, 2010, 2:55 pm

¡Hola!

Yo sé que este post es viejo para pensar que he benwade9721 quieres hacer es algo como:
Código: [ Select ]
<?
class Class_One {
 
  var $name;

  public static function getInst ($my_string) {
    return new Class_One ($my_string);
  }
 
  function __construct($my_string) {
    $this->name = $my_string;
    echo 'Hello ' . $this->name;
  }
 
  function function_one() {
    echo 'Hello World';
  }

}

class Class_Two {

  function __construct() {
    //$new_class_instance = new Class_One('Joan');
    $new_class_instance = Class_one::getInst ('Joan');
    $new_class_instance->function_one ();
  }
}
?>
  1. <?
  2. class Class_One {
  3.  
  4.   var $name;
  5.   public static function getInst ($my_string) {
  6.     return new Class_One ($my_string);
  7.   }
  8.  
  9.   function __construct($my_string) {
  10.     $this->name = $my_string;
  11.     echo 'Hello ' . $this->name;
  12.   }
  13.  
  14.   function function_one() {
  15.     echo 'Hello World';
  16.   }
  17. }
  18. class Class_Two {
  19.   function __construct() {
  20.     //$new_class_instance = new Class_One('Joan');
  21.     $new_class_instance = Class_one::getInst ('Joan');
  22.     $new_class_instance->function_one ();
  23.   }
  24. }
  25. ?>

en itll esperanza de ser útiles
  • Anonymous
  • Bot
  • No Avatar
  • Registrado: 25 Feb 2008
  • Mensajes: ?
  • Loc: Ozzuland
  • Status: Online

Nota Octubre 30th, 2010, 2:55 pm

Publicar Información

  • Total de mensajes en este tema: 16 mensajes
  • Usuarios navegando por este Foro: No hay usuarios registrados visitando el Foro y 110 invitados
  • No puede abrir nuevos temas en este Foro
  • No puede responder a temas en este Foro
  • No puede editar sus mensajes en este Foro
  • No puede borrar sus mensajes en este Foro
  • No puede enviar adjuntos en este Foro
 
 

© 2011 Unmelted, LLC. Ozzu® es una marca registrada de Unmelted, LLC