Skip to content

Instantly share code, notes, and snippets.

@steveathon
Created March 8, 2015 08:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save steveathon/09cab0e6ce27ad864de5 to your computer and use it in GitHub Desktop.
Save steveathon/09cab0e6ce27ad864de5 to your computer and use it in GitHub Desktop.
IF Resource Evaluation test
<?php
if ( $ch = curl_init() && curl_setopt($ch,CURLOPT_AUTOREFERER,FALSE) ) {
echo "Passed this test.\r\n";
}
else {
echo "Failed this test.\r\n";
}
class moo {
function test() {
if ($this->ch = curl_init() && curl_setopt($this->ch,CURLOPT_AUTOREFERER,FALSE) ) {
echo "Passed this test.\r\n";
}
else {
echo "Failed this test.\r\n";
}
}
}
$Moo = new moo();
$Moo->test();
?>
All of these tests above fail with the erorr, that there is no valid resource on $ch available to setopt functions.
With that in mind, switching it to OR, in the form of:
<?php
if ( $ch = curl_init()
|| curl_setopt($ch,CURLOPT_AUTOREFERER,FALSE) ) {
echo "Passed this test.\r\n";
}
else {
echo "Failed this test.\r\n";
}
?>
Passes the test.
@steveathon
Copy link
Author

As an aside, wrapping the call inside another bracket works:

    if ( ($ch = curl_init() )
&& curl_setopt($ch,CURLOPT_AUTOREFERER,FALSE) ) {
        echo "Passed this test.\r\n";
    }
    else {
        echo "Failed this test.\r\n";
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment