ZF-5413: using "$var === null" instaed of "is_null($var)"

Description

Comments

benchmark:


echo '"is_null($var)" vs. "$var === null"'."\n";
$max = 100000;
$varNull    = null;
$varNotNull = true;

echo ' is_null($var): ';
$start = microtime(true);
for ($i=0; $i<$max; $i++) {
    is_null($varNull);
    is_null($varNotNull);
}
$end = microtime(true);
echo ($end-$start)."\n";

echo ' $var === null: ';
$start = microtime(true);
for ($i=0; $i<$max; $i++) {
    ($varNull === null);
    ($varNotNull === null);
}
$end = microtime(true);
echo ($end-$start)."\n";

output:


"is_null($var)" vs. "$var === null"
 is_null($var): 0.0468430519104
 $var === null: 0.0156960487366

Changes integrated with r13522

2 parse errors found in:

Zend\Db\Adapter\Pdo\Oci.php on line 174 Zend\Gdata\Gapps\Extension\Login.php on line 478

Reopening due to parse errors reported.

They were fixed by Thomas :D

I see no problems at all with latest trunk. Zend Studio shows no parsing errors and unit tests are running without problems.

Therefor unassigning this issue as this problem seems to be OS specific.

.../zf-trunk$ grep -iHrn 'is_null' library/* | grep -v '\/.svn'

library/Zend/Controller/Action/Helper/Cache.php:226: if (!is_null($this->_manager)) { library/Zend/Cache/Frontend/Capture.php:78: if (is_null($id)) { library/Zend/Cache/Backend/Static.php:169: if (is_null($this->_tagged) && $tagged = $this->getInnerCache()->load(self::INNER_CACHE_NAME)) { library/Zend/Cache/Backend/Static.php:214: if (is_null($id) || strlen($id) == 0) { library/Zend/Cache/Backend/Static.php:228: if (is_null($id) || strlen($id) == 0) { library/Zend/Cache/Backend/Static.php:242: if (is_null($this->_tagged) && $tagged = $this->getInnerCache()->load(self::INNER_CACHE_NAME)) { library/Zend/Cache/Backend/Static.php:244: } elseif (is_null($this->_tagged)) { library/Zend/Cache/Backend/Static.php:308: if (is_null($this->_tagged) && $tagged = $this->getInnerCache()->load(self::INNER_CACHE_NAME)) { library/Zend/Cache/Backend/Static.php:397: if (is_null($this->_tagged) && $tagged = $this->getInnerCache()->load(self::INNER_CACHE_NAME)) { library/Zend/Cache/Backend/Static.php:415: if (is_null($this->_tagged)) { library/Zend/Cache/Backend/Static.php:419: if (is_null($this->_tagged) || empty($this->_tagged)) { library/Zend/Cache/Backend/Static.php:437: if (is_null($this->_tagged)) { library/Zend/Cache/Backend/Static.php:441: if (is_null($this->_tagged) || empty($this->_tagged)) { library/Zend/Cache/Backend/Static.php:484: if (is_null($this->_tagCache)) { library/Zend/Gdata/App/Base.php:378: (is_null($majorVersion) ? 'NULL' : $majorVersion) . library/Zend/Gdata/App/Base.php:379: ' '. (is_null($minorVersion) ? 'NULL' : $minorVersion); library/Zend/Service/WindowsAzure/Credentials/SharedKey.php:106: if (!is_null($headers)) { library/Zend/Service/WindowsAzure/Storage.php:201: if (is_null($this->_credentials)) { library/Zend/Service/WindowsAzure/Storage.php:207: if (is_null($this->_retryPolicy)) { library/Zend/Service/WindowsAzure/Storage.php:243: if (is_null($this->_retryPolicy)) { library/Zend/Service/WindowsAzure/Storage.php:360: if (is_null($headers)) { library/Zend/Service/WindowsAzure/Storage.php:409: if (is_null($response)) { library/Zend/Service/WindowsAzure/Storage.php:488: if (is_null($timestamp)) { library/Zend/Service/WindowsAzure/Storage/Queue.php:281: if (!is_null($prefix)) { library/Zend/Service/WindowsAzure/Storage/Queue.php:284: if (!is_null($maxResults)) { library/Zend/Service/WindowsAzure/Storage/Queue.php:287: if (!is_null($marker)) { library/Zend/Service/WindowsAzure/Storage/Queue.php:298: if (!is_null($xmlQueues)) { library/Zend/Service/WindowsAzure/Storage/Queue.php:306: if (!is_null($maxResults) && $currentResultCount < $maxResults) { library/Zend/Service/WindowsAzure/Storage/Queue.php:307: if (!is_null($xmlMarker) && $xmlMarker != '') { library/Zend/Service/WindowsAzure/Storage/Queue.php:311: if (!is_null($maxResults) && count($queues) > $maxResults) { library/Zend/Service/WindowsAzure/Storage/Queue.php:343: if (!is_null($ttl) && ($ttl <= 0 || $ttl > self::MAX_MESSAGE_SIZE)) { library/Zend/Service/WindowsAzure/Storage/Queue.php:349: if (!is_null($ttl)) { library/Zend/Service/WindowsAzure/Storage/Queue.php:388: if (!is_null($visibilityTimeout) && ($visibilityTimeout <= 0 || $visibilityTimeout > 7200)) { library/Zend/Service/WindowsAzure/Storage/Queue.php:400: if (!$peek && !is_null($visibilityTimeout)) { library/Zend/Service/WindowsAzure/Storage/Blob/Stream.php:93: if (is_null($this->_storageClient)) { library/Zend/Service/WindowsAzure/Storage/Blob/Stream.php:374: if (!is_null($info)) { library/Zend/Service/WindowsAzure/Storage/Blob/Stream.php:459: if (!is_null($info)) { library/Zend/Service/WindowsAzure/Storage/TableEntityQuery.php:132: if (!is_null($value)) { library/Zend/Service/WindowsAzure/Storage/TableEntityQuery.php:214: if (!is_null($this->_top)) { library/Zend/Service/WindowsAzure/Storage/TableEntityQuery.php:237: if (!is_null($this->_partitionKey)) { library/Zend/Service/WindowsAzure/Storage/TableEntityQuery.php:241: if (!is_null($this->_partitionKey) && !is_null($this->_rowKey)) { library/Zend/Service/WindowsAzure/Storage/TableEntityQuery.php:245: if (!is_null($this->_rowKey)) { library/Zend/Service/WindowsAzure/Storage/DynamicTableEntity.php:89: if (is_null($type)) { library/Zend/Service/WindowsAzure/Storage/BatchStorageAbstract.php:78: if (!is_null($batch) && $this->isInBatch()) { library/Zend/Service/WindowsAzure/Storage/BatchStorageAbstract.php:101: return !is_null($this->_currentBatch); library/Zend/Service/WindowsAzure/Storage/Batch.php:152: if (is_null($headers)) { library/Zend/Service/WindowsAzure/Storage/Batch.php:164: if (is_null($rawData)) { library/Zend/Service/WindowsAzure/Storage/Table.php:189: if (!is_null($response->getHeader('x-ms-continuation-NextTableName'))) { library/Zend/Service/WindowsAzure/Storage/Table.php:300: if (is_null($entity)) { library/Zend/Service/WindowsAzure/Storage/Table.php:370: if (is_null($entity)) { library/Zend/Service/WindowsAzure/Storage/Table.php:526: if (!is_null($nextPartitionKey) && !is_null($nextRowKey)) { library/Zend/Service/WindowsAzure/Storage/Table.php:605: if (!is_null($response->getHeader('x-ms-continuation-NextPartitionKey')) && !is_null($response->getHeader('x-ms-continuation-NextRowKey'))) { library/Zend/Service/WindowsAzure/Storage/Table.php:692: if (is_null($entity)) { library/Zend/Service/WindowsAzure/Storage/Table.php:797: if (is_null($azureValue->Value)) { library/Zend/Service/WindowsAzure/Storage/Table.php:802: if (!is_null($azureValue->Value)) { library/Zend/Service/WindowsAzure/Storage/TableEntity.php:266: if (!is_null($accessor)) { library/Zend/Service/WindowsAzure/Storage/TableEntity.php:275: if (!is_null($accessor)) { library/Zend/Service/WindowsAzure/Storage/Blob.php:472: if (!is_null($prefix)) { library/Zend/Service/WindowsAzure/Storage/Blob.php:475: if (!is_null($maxResults)) { library/Zend/Service/WindowsAzure/Storage/Blob.php:478: if (!is_null($marker)) { library/Zend/Service/WindowsAzure/Storage/Blob.php:489: if (!is_null($xmlContainers)) { library/Zend/Service/WindowsAzure/Storage/Blob.php:499: if (!is_null($maxResults) && $currentResultCount < $maxResults) { library/Zend/Service/WindowsAzure/Storage/Blob.php:500: if (!is_null($xmlMarker) && $xmlMarker != '') { library/Zend/Service/WindowsAzure/Storage/Blob.php:504: if (!is_null($maxResults) && count($containers) > $maxResults) { library/Zend/Service/WindowsAzure/Storage/Blob.php:1138: if (!is_null($prefix)) { library/Zend/Service/WindowsAzure/Storage/Blob.php:1144: if (!is_null($maxResults)) { library/Zend/Service/WindowsAzure/Storage/Blob.php:1147: if (!is_null($marker)) { library/Zend/Service/WindowsAzure/Storage/Blob.php:1159: if (!is_null($xmlBlobs)) { library/Zend/Service/WindowsAzure/Storage/Blob.php:1179: if (!is_null($xmlBlobs)) { library/Zend/Service/WindowsAzure/Storage/Blob.php:1199: if (!is_null($maxResults) && $currentResultCount < $maxResults) { library/Zend/Service/WindowsAzure/Storage/Blob.php:1200: if (!is_null($xmlMarker) && $xmlMarker != '') { library/Zend/Service/WindowsAzure/Storage/Blob.php:1204: if (!is_null($maxResults) && count($blobs) > $maxResults) { library/Zend/Service/Twitter.php:148: if (is_null($consumer)) { library/Zend/Service/DeveloperGarden/Client/ClientAbstract.php:337: if (!is_null($wsdlCache)) { library/Zend/Service/DeveloperGarden/Client/Soap.php:112: if (!is_null($this->_tokenService)) { library/Zend/Service/DeveloperGarden/LocalSearch/SearchParameters.php:525: if (is_null($value)) { library/Zend/Service/Simpy.php:89: $query = array_diff($query, array_filter($query, 'is_null')); library/Zend/Service/Amazon/S3.php:521: $headers['x-amz-metadata-directive'] = is_null($meta) ? 'COPY' : 'REPLACE'; library/Zend/Log/Filter/Priority.php:62: $this->_operator = is_null($operator) ? '<=' : $operator; library/Zend/Crypt/Math/BigInteger.php:64: if (!is_null($extension) && !in_array($extension, array('bcmath', 'gmp', 'bigint'))) { library/Zend/Crypt/Math/BigInteger.php:93: if (is_null($extension)) { library/Zend/Crypt/Rsa/Key/Private.php:65: if (is_null($this->_publicKey)) { library/Zend/Crypt/Rsa.php:193: if (!is_null($configargs)) { library/Zend/Crypt/DiffieHellman.php:111: if (!is_null($privateKey)) { library/Zend/Crypt/DiffieHellman.php:173: if (is_null($this->_publicKey)) { library/Zend/Validate/NotEmpty.php:154: if (!is_null($value) && !is_string($value) && !is_int($value) && !is_float($value) && library/Zend/Validate/NotEmpty.php:175: if (is_null($value)) { library/Zend/Feed/Reader/Extension/EntryAbstract.php:86: if (!is_null($type)) { library/Zend/Feed/Reader/Extension/Atom/Entry.php:587: if (!is_null($this->getBaseUrl())) { library/Zend/Feed/Reader/Extension/Atom/Feed.php:518: if (!is_null($this->getBaseUrl())) { library/Zend/Feed/Reader/Feed/Rss.php:181: if (!$copyright && !is_null($this->getExtension('DublinCore'))) { library/Zend/Feed/Reader/Feed/Rss.php:347: if (!$description && !is_null($this->getExtension('DublinCore'))) { library/Zend/Feed/Reader/Feed/Rss.php:382: if (!$id && !is_null($this->getExtension('DublinCore'))) { library/Zend/Feed/Reader/Feed/Rss.php:477: if (!$language && !is_null($this->getExtension('DublinCore'))) { library/Zend/Feed/Reader/Feed/Rss.php:546: if (is_null($link) || empty($link)) { library/Zend/Feed/Reader/Feed/Rss.php:615: if (!$title && !is_null($this->getExtension('DublinCore'))) { library/Zend/Feed/Reader/Feed/Atom.php:321: if (is_null($link) || empty($link)) { library/Zend/Feed/Reader/FeedSet.php:91: if (!is_null($uri)) { library/Zend/Feed/Writer/Entry.php:215: if (is_null($date)) { library/Zend/Feed/Writer/Entry.php:236: if (is_null($date)) { library/Zend/Feed/Writer/Extension/Threading/Renderer/Entry.php:93: if (!is_null($count)) { library/Zend/Feed/Writer/Extension/Threading/Renderer/Entry.php:119: if (!is_null($count)) { library/Zend/Feed/Writer/Extension/Threading/Renderer/Entry.php:137: if (is_null($count)) { library/Zend/Feed/Writer/Extension/ITunes/Renderer/Entry.php:107: if (is_null($block)) { library/Zend/Feed/Writer/Extension/ITunes/Renderer/Entry.php:147: if (is_null($explicit)) { library/Zend/Feed/Writer/Extension/ITunes/Renderer/Feed.php:112: if (is_null($block)) { library/Zend/Feed/Writer/Extension/ITunes/Renderer/Feed.php:203: if (is_null($explicit)) { library/Zend/Feed/Writer/Feed/FeedAbstract.php:174: if (is_null($date)) { library/Zend/Feed/Writer/Feed/FeedAbstract.php:195: if (is_null($date)) { library/Zend/Feed/Writer/Feed/FeedAbstract.php:216: if (is_null($date)) { library/Zend/Feed/Writer/Deleted.php:129: if (is_null($date)) { library/Zend/Feed/Pubsubhubbub/Subscriber/Callback.php:211: if (is_null($this->_feedUpdate)) { library/Zend/Feed/Pubsubhubbub/Model/ModelAbstract.php:56: if (is_null($tableGateway)) { library/Zend/Feed/Pubsubhubbub/Subscriber.php:153: if (!is_null($config)) { library/Zend/Feed/Pubsubhubbub/Subscriber.php:474: if (empty($value) || (!is_string($value) && !is_null($value))) { library/Zend/Feed/Pubsubhubbub/Subscriber.php:736: if ($mode == 'subscribe' && !is_null($this->getLeaseSeconds())) { library/Zend/Feed/Pubsubhubbub/Publisher.php:77: if (!is_null($config)) { library/Zend/Feed/Pubsubhubbub/Publisher.php:309: if (empty($value) || (!is_string($value) && !is_null($value))) { library/Zend/Feed/Pubsubhubbub/CallbackAbstract.php:77: if (!is_null($config)) { library/Zend/Feed/Reader.php:239: if (is_null($etag)) { library/Zend/Feed/Reader.php:242: if (is_null($lastModified)) { library/Zend/Filter/Compress/Rar.php:179: if (is_null($callback)) { library/Zend/Filter/Compress/Rar.php:213: if (!is_null($password)) { library/Zend/Filter/Boolean.php:276: if (is_null($value)) { library/Zend/Tool/Framework/Metadata/Basic.php:206: if (is_null($varValue)) { library/Zend/Ldap/Filter.php:245: if (!is_null($prepend)) $str .= $prepend; library/Zend/Ldap/Filter.php:247: if (!is_null($append)) $str .= $append; library/Zend/Ldap/Attribute.php:56: if (!is_null($v)) $valArray[] = $v; library/Zend/Ldap/Attribute.php:59: else if (!is_null($value)) library/Zend/Ldap/Attribute.php:62: if (!is_null($value)) $valArray[] = $value; library/Zend/Ldap/Attribute.php:87: if (is_null($index)) { library/Zend/Ldap/Attribute.php:347: if (!is_null($v)) $convertedValues[] = $v; library/Zend/Ldap/Attribute.php:350: else if (!is_null($value)) { library/Zend/Ldap/Attribute.php:352: if (!is_null($value)) $convertedValues[] = $value; library/Zend/Ldap/Node.php:102: if (!is_null($ldap)) $this->attachLdap($ldap); library/Zend/Ldap/Node.php:139: if (is_null($this->_ldap)) { library/Zend/Ldap/Node.php:208: return (!is_null($this->_ldap)); library/Zend/Ldap/Dn.php:613: if (!is_null($keys)) $keys = $k; library/Zend/Ldap/Dn.php:614: if (!is_null($vals)) $vals = $v; library/Zend/Amf/Server.php:610: if (is_null($request) || !$request instanceof Zend_Amf_Request) { library/Zend/Oauth/Client.php:81: if (!is_null($oauthOptions)) { library/Zend/Oauth/Client.php:220: if (!is_null($method)) { library/Zend/Oauth/Signature/SignatureAbstract.php:118: if (!is_null($this->_tokenSecret)) { library/Zend/Oauth/Signature/Plaintext.php:43: if (is_null($this->_tokenSecret)) { library/Zend/Oauth/Token/AuthorizedRequest.php:47: if (!is_null($data)) { library/Zend/Oauth/Token/AuthorizedRequest.php:54: if (!is_null($utility)) { library/Zend/Oauth/Http/Utility.php:63: if (!is_null($serviceProviderParams)) { library/Zend/Oauth/Config.php:159: if (!is_null($options)) { library/Zend/Oauth/Config.php:270: if (!is_null($this->_rsaPrivateKey)) { library/Zend/Oauth/Token.php:71: if (!is_null($response)) { library/Zend/Oauth/Token.php:78: if (!is_null($utility)) { library/Zend/Oauth/Token.php:281: if (is_null($this->_httpUtility)) { library/Zend/Oauth/Consumer.php:82: if (!is_null($options)) { library/Zend/Oauth/Consumer.php:105: if (is_null($request)) { library/Zend/Oauth/Consumer.php:107: } elseif(!is_null($customServiceParameters)) { library/Zend/Oauth/Consumer.php:110: if (!is_null($httpMethod)) { library/Zend/Oauth/Consumer.php:137: if (is_null($redirect)) { library/Zend/Oauth/Consumer.php:139: } elseif(!is_null($customServiceParameters)) { library/Zend/Oauth/Consumer.php:142: if (!is_null($token)) { library/Zend/Oauth/Consumer.php:190: if (is_null($request)) { library/Zend/Oauth/Consumer.php:195: if (!is_null($authorizedToken->getParam('oauth_verifier'))) { library/Zend/Oauth/Consumer.php:201: if (!is_null($httpMethod)) { library/Zend/Oauth/Http.php:89: if (!is_null($parameters)) { library/Zend/Oauth/Http.php:92: if (!is_null($utility)) { library/Zend/Oauth/Http.php:180: if (!is_null($response)) { library/Zend/Oauth/Http.php:184: if (is_null($response) // Request failure/exception library/Zend/Oauth/Http.php:236: . (!is_null($response) library/Zend/View/Helper/HeadTitle.php:73: if (is_null($setType) && is_null($this->getDefaultAttachOrder())) { library/Zend/View/Helper/HeadTitle.php:75: } elseif (is_null($setType) && !is_null($this->getDefaultAttachOrder())) { library/Zend/Soap/Wsdl/Strategy/DefaultComplexType.php:77: if (is_null($defaultProperties[$propertyName])) { library/Zend/Queue/Stomp/Frame.php:198: return is_null($this->_body) library/Zend/Queue/Stomp/Frame.php:214: if (!is_string($body) && !is_null($body)) { library/Zend/Queue/Stomp/Frame.php:232: return is_null($this->_command) library/Zend/Queue/Stomp/Frame.php:246: if (!is_string($command) && !is_null($command)) { library/Zend/Ldap.php:982: if (!is_null($sort) && is_string($sort)) { library/Zend/Ldap.php:1159: if (is_null($v)) unset($value[$i]); library/Zend/Ldap.php:1173: if (is_null($value)) $entry[$key] = array();

fixed with:

find library/ -type f -name ".php" -exec sed -i -r 's#[^!]is_null\s(([^()]))#(\1 === NULL)#g' {} \; find library/ -type f -name ".php" -exec sed -i -r 's#[!]is_null\s(([^()]))#(\1 !== NULL)#g' {} \;

Here are the corrected commands:

 
find library/ -type f -name "*.php" -exec sed -i -r 's#([^\!])is_null\s*\(([^\(\)]*)\)#\1\2 === null#g' {} \;
find library/ -type f -name "*.php" -exec sed -i -r 's#[\!]is_null\s*\(([^\(\)]*)\)#\1 !== null#g' {} \;

changed fix version because it's currently not merged to branch

I don't believe this actually made it into 1.10.8...