Durgaprasad
Durgaprasad

Reputation: 157

how to echo variable outside of class, passing from function within class

I have a php code. my code is like this
class Connection {
function connect(){
$link = 'Connected';
}
}

$con = new Connection();
$con -> connect();
echo $con->link;//connected
here i want to echo the variable but it is not getting Help me

Upvotes: 0

Views: 219

Answers (1)

Thomas
Thomas

Reputation: 417

You will have to return a value, like this:

function connect() {
    return 'Connected';
}

Upvotes: 2

Related Questions