Industrial
Industrial

Reputation: 42778

PHP: Erratic behaviour of functions?

What on earth is PHP doing here?

This first line works perfectly, but when I try to check whether the return of the parse_url is empty or not, my whole execution is stopped and the infamous White screen appears:

Working:

$subFolderCheck = ( strlen( parse_url('http://www.example.com', PHP_URL_PATH)) >1  ? true : false);

Making my script go bananas:

$subFolderCheck = ( empty( parse_url('http://www.example.com', PHP_URL_PATH))  ? true : false);

Upvotes: 0

Views: 95

Answers (1)

Shakti Singh
Shakti Singh

Reputation: 86406

Here it is explained.

you can not call a function inside empty function

Note:

empty() only checks variables as anything else will result in a parse error. In other words, the following will not work: empty(trim($name)).

You could assign the return value in variable and check that variable with empty

$subFolderCheck=(parse_url('http://www.example.com', PHP_URL_PATH))  ? true : false);

if (empty($subFolderCheck))
{
  //do stuff
}

Upvotes: 4

Related Questions