Foros del Web » Programando para Internet » PHP »

problemas con objetos

Estas en el tema de problemas con objetos en el foro de PHP en Foros del Web. Mi problema es el siguiente: quiero tener un boton html para instanciar un objeto, y otro boton html para ejecutar un metodo de ese objeto. ...
  #1 (permalink)  
Antiguo 18/09/2006, 06:03
 
Fecha de Ingreso: septiembre-2006
Mensajes: 1
Antigüedad: 17 años, 7 meses
Puntos: 0
problemas con objetos

Mi problema es el siguiente:

quiero tener un boton html para instanciar un objeto, y otro boton html para ejecutar un metodo de ese objeto. Si la definicion de la clase esta en otro archivo me da este error:

Fatal error: Unknown(): The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition test1 of the object you are trying to operate on was loaded _before_ the session was started in c:\inetpub\wwwroot\problema.php on line 11

pego el codigo:

archivo prueba_obj.php que contiene la clase:
Código PHP:
<?php
class test1{
    var 
$info=array("firm" => "NULL","mac" => "NULL","fecha" => "NULL","ip"=>"null");    
    function 
hacer($data){
        echo 
"<br>"." HOLA: ".$data."<br>";
        }    
    function 
test($ip){
        
$this->info['ip']=$ip;
    }
}
?>
archivo problema.php que contiene el script
Código PHP:
<?php
session_start
();
include 
'prueba_obj.php';



    if(isset(
$_GET['creartest'])){    
    
$_SESSION['mitest']=new test1("172.31.1.213");    
    
$_SESSION['mitest']->hacer("hola carga 1");
        }
        
    if(isset(
$_GET['prueba'])){        
    if (isset(
$_SESSION['mitest']))$_SESSION['mitest']->hacer("hola carga 2");    
        }
        
        

    
?>    
    
        <form>
        <form target="" action="#" method="get">        
        <input type="hidden" name="creartest">                  
         <input type="submit" value ="crear un test">
        </form>
    
        
        <form target=""  action="#" method="get">            
        <input type="hidden" name="prueba" value=0>
        <input type="submit" value ="prueba">            
        </form>    
        
    </body>    
</html>

Si lo pongo todo en el mismo archivo y no uso un inlcude funciona ok...

A ver si alguien sabe algo...

Saludos
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 08:17.