Reputation: 1682
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;
Upvotes: 1
Views: 76
Reputation: 107
To access your variable like
$obj -> variable;
You need to make like this:
class MyClass(){
var prop;
var variable;
function myfunc(){
$this->variable = 'value';
}
}
Upvotes: 1
Reputation: 230
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
Upvotes: 2