Changing is_null($x) to null === $x or !is_null($x) to null !== $x in PHP files

Here is a script that can perform the change of is_null($x) to null === $x (and the negation).

1 2 3 4 5 6 7 8 9
#!/bin/bash
 
# Assume we look in tmp
 
# For is_null
find tmp/ -type f -name "*.php" -exec sed -i -r 's#\([^\!]\)is_null\s*(\([^()]*\))#\1\2 === null#g' {} \;
 
# For !is_null
find tmp/ -type f -name "*.php" -exec sed -i -r 's#[\!]is_null\s*(\([^()]*\))#\1 !== null#g' {} \;
view raw is_null.sh This Gist brought to you by GitHub.

Note I am not the original author of this script, however, I do not have the original source.

Note: this is a micro-optimisation, however, it does enable for nicer code in any case.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>