PHP Killer: Do not do this on your code

Unless you want/need to kill some time… do not do the following on your PHP code, or you will be banging your head against the wall:

 

1. Use trim() inside empty():

 

sample:

if (!empty(trim($item))) {

}

 

work around:

$item = trim($item);

if (!empty($item)) {

}

 

 

2. Typecast a parameter that is sent by reference to a function:

$random = shuffle((array) $items);

 

workround:

$items = (array) $items;

$random = shuffle($items);

 

 

 

Bookmark the permalink.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

  • IGlr