Hello,

I wan to use a class variable out side a class and inside in different functions but try it but didn't work, here's an example:

class Operation {
var $Variable;

function One() {
$this->Variable = do stuff......
}

function Two() {
$other_value = do more stuff $this->Variable
}

}

$op = new Operation();

$op->One()
... do stuff with $op->Variable;

$op->Two()
... do another stuff with $op->Variable;

Thank you in advance

    Afraid I don't understand what the problem is. If what you mean is you want to reference an object from within a separate user-defined function, then you'll want to pass that object to the function as one of its arguments.

    function example($obj)
    {
       echo $obj->Variable;
    }
    
    $op = new Operation();
    $op->One();
    example($op);
    

    Assuming you are using PHP5+ (and if not, why not?) you can use type hinting to require that an object of the correct type is passed to the function:

    function example(Operation $obj)
    {
       echo $obj->Variable;
    }
    
      Write a Reply...