简体   繁体   中英

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

You will have to return a value, like this:

function connect() {
    return 'Connected';
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM