What is this?

Many times, we struggled on finding out the cause of error. Especially, it works on local environment, but failed in live server.

For some hosting, especially shared hosting, we have no freedom to change the php settings and we have to guess which section caused the error and what is it about.

This usually caused us hours & hours to figure it out.

Thus, I wrote this post.

Please comment on below OR drop me an email at me@jsl.im, if you want to contribute to this post.

Thanks

Errors

1. Can't use method return value in write context

Failed example

1
2
3
4
<?php
if (empty($obj->method())) {
// do something
}

Correct way

1
2
3
4
5
6
<?php
$result = $obj->method();
if (empty($result)) {
// do something
}

Move the result out as a separate variable, even though it may not be use in the section below.

Reference: Can't use method return value in write context

Contributors

  • Js Lim