Archive for the ‘PHP News’ Category

filter_input() return value, an undesired result

September 27, 2010 Leave a comment

I love PHP built in filter functions… but in this use case, they always trick me:

I ran this on the command line:

$_GET['name'] = 32;

var_dump(filter_input(INPUT_GET, "name", FILTER_VALIDATE_INT));

I got null, when I should get (int) 32.

However, if I type in a browser, say the page is test.php … test.php?name = 32

and run the code

var_dump(filter_input(INPUT_GET, "name", FILTER_VALIDATE_INT));

I get the right answer (int) 32.

Evidently the built in filter functions treat $_GET[‘name’] differently in the script, than when it is actually passed over $_GET…

Go figure.

Categories: PHP News

Ubuntu 10.04 PHP Error Reporting is turned off.

September 4, 2010 Leave a comment

Some call it a feature… but if you’re doing PHP in Ubuntu 10.04 and you get an error, you might get a blank page instead of the error message you were expecting.

The solution, assuming you are using a test server not a production server, is to turn those errors on.

sudo gedit /etc/php5/apache2/php.ini

Set display_errors = On

restart your apache server: sudo /etc/init.d/apache2 restart

Now you can see your errors and move on with your life.

Categories: PHP News