Archive for September, 2011

Cool PHP error-suppressing operator – the @ operator

Today by accident I get new php syntax – the @ operator
I often see code
if ( isset($REQUEST[‘someName’] && … ) {

}

The `…` in the if statement is the real/futher expression usage on
isset($REQUEST[‘someName’]

 

With @, this isset(…) stuff is no longer needed

e.g.
<?php

$a

= array(‘a’=>1, ‘bb’=>22);

echo ‘<h2>error</h2>’;
$b = $a[‘ccc’]==333 ? 1 : 2;
echo $b;

echo ‘<h1>no-error</h1>’;
$b = @$a[‘ccc’]==333 ? 1 : 2;
echo $b;

To me, the @ operator saves & eases myself from worrying if a field in the `$_REQUEST`/array already exists or not. With @, I just call it out and write the expression/condition for it without bothering to start with isset(…) any longer!

Hope you would share this cool operator with me!
Nam

ref.
http://www.php.net/manual/en/language.operators.errorcontrol.php

Advertisements

PHP – `php.ini` file for Apache and PHP CLI (command line) is NOT the same

Today, after spending 3 days (yes 3 days!) trying to install PHPUnit on my Windows 7 machine, I realize that `php.ini` used by the PHP CLI is not the same with Apache server.

Quoted from Danial Brown from php.net “If there’s no php.ini file in the path it’s checking, it’ll just
use the internal defaults.  You may not have a php.ini file anywhere
on your system, which is okay if you don’t need to do any tuning.”

And from Stephen “If you have one, it is likely in: <php>\php.ini”

So, I just write this down so as we can find it on the internet when we run into PHP-related installation like this. Hope that you would find it helpful!

Nam