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;
}
}?>
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