Ver Mensaje Individual
  #1 (permalink)  
Antiguo 19/02/2012, 07:02
Avatar de OsSk4R
OsSk4R
 
Fecha de Ingreso: octubre-2006
Ubicación: $this->home
Mensajes: 824
Antigüedad: 17 años, 6 meses
Puntos: 74
Object of class Main could not be converted to string

Buenas,
Veréis, estoy creando un script y resulta que me he encontrado con un error que no logro entender porque sucede.

Este es el código:
Código PHP:
Ver original
  1. <?php
  2. class Main {
  3.     private $ruta;
  4.     private $accion;
  5.     public function __construct() {
  6.         require_once("Config/Config.php");;
  7.     }
  8.     public function main() {
  9.         $this->ruta = $_GET['page'];
  10.         $this->accion = $_GET['accion'];
  11.         if(isset($this->ruta) && isset($this->accion)):
  12.             require_once(PAGES . $this->ruta . DIRECTORY_SEPARATOR . 'class' . $this->ruta . '.php');
  13.             $objeto = new $this->ruta();
  14.             $objeto->$this->accion();
  15.         elseif(isset($this->ruta)):
  16.             require_once(PAGES . $this->ruta . DIRECTORY_SEPARATOR . 'class' . $this->ruta . '.php');
  17.             $obj = new $this->ruta();
  18.         else:
  19.             echo 'No se pudo cargar la página';
  20.         endif;
  21.     }
  22. }
Pues bien, al ejecutarlo me tira el siguiente error:
Cita:
Catchable fatal error: Object of class Main could not be converted to string in
SIn embargo, si ahora hago así:
Código PHP:
Ver original
  1. class Main {
  2.     private $ruta;
  3.     private $accion;
  4.     public function __construct() {
  5.         require_once("Config/Config.php");;
  6.     }
  7.     public function main() {
  8.         $ruta = $_GET['page'];
  9.         $accion = $_GET['accion'];
  10.         if(isset($ruta) && isset($accion)):
  11.             require_once(PAGES . $ruta . DIRECTORY_SEPARATOR . 'class' . $ruta . '.php');
  12.             $objeto = new $ruta();
  13.             $objeto->$accion();
  14.         elseif(isset($ruta)):
  15.             require_once(PAGES . $ruta . DIRECTORY_SEPARATOR . 'class' . $ruta . '.php');
  16.             $obj = new $ruta();
  17.         else:
  18.             echo 'No se pudo cargar la página';
  19.         endif;
  20.     }
  21. }
Me funciona bien.
¿A que se debe ese error? ¡No lo comprendo!

Un saludo y muchas gracias