从外部访问对象内的函数变量

Following this structure:

class MyClass(){
   var prop;

   function myfunc(){
      $variable = 'value';
   }
}

$obj = new MyClass;

Is there a way i can access '$variable' from outside without a return?

I can get a property like this:

$obj -> prop;

but i can't access the '$variable' like this:

$obj -> variable;
class MyClass(){
   public prop;
   public variable;    

   function myfunc(){
      $this->variable = 'value';
   }
}

using var inside the class is not recommended. instead of that you can use public

$obj -> variable; now you can access this from out side the class scope

To access your variable like

$obj -> variable;

You need to make like this:

class MyClass(){
   var prop;
   var variable;    

   function myfunc(){
      $this->variable = 'value';
   }
}