lundi 18 septembre 2017

PHP calling a method and checking return simultaneously

I'm new the PHP, and had a very simple question. I've seen people call and return statements in the conditional of the if statement. For example

if ($connection = @ssh2_connect($host, 22)) { do something };

If I am not wrong this will check the return boolean as well as create the connection. Will this work for everything? More specifically, for fclose(), I want to know if I do something like this:

if (fclose($stream)) { do something };  

will actually close the check the boolean return value of it AND close the stream. Or do I have to do this?

...
fclose($stream);
if (fclose($stream)) { do something };  
...

Aucun commentaire:

Enregistrer un commentaire