Thursday September 9, 2010 @ 21:52:04 GMT+10    ( Weather:  21°C / 70°F  -  Mostly Cloudy )
Home » Weblog Archives

Powered byD's Bloggie
Weblog » Archive » 2005 » October » Day 16
Browse by day ...
 14 October, 200517 October, 2005 

Changing Weather - 12:12 pm
Personal  -  poster 

Just woke up, it's noon on weekend but the sky looks like 5am in the morning. Weather is changing and has been raining for 3 days. It will continue for a couple of days before the weather truely turns warm again. The cold weather makes people feel lazy ~~

Last edited: Mon 2005-10-17 @ 19:01 , by DaRen 1 time(s)

PHP Passing by Reference - 3:07 pm
Bug , Coding , PHP  -  poster 

PHP's function supports passing by reference. However, default values may ONLY be passed by reference starting from PHP >= 5. Default values in PHP functions are like:
[ Hide ]
[ Highlight ] [ Text ]
// function declaration with default value
function foo($bar = 'default value here'){ ... };
// function declaration with passing by reference
function foo(&$bar){ ... };


What pissed me off is that I'm using PHP 5 for my computer but the hosting server is using PHP4. I only realize that PHP 4 doesn't supports that after I uploaded all my files to the server. Example of default values passed by reference:
[ Hide ]
[ Highlight ] [ Text ]
// This won't work in PHP < 5
function foo(&$bar = 'default value here'){ ... };


Workaround :
Set allow_call_time_pass_reference to true in php.ini if you're using php >= 5 so that you won't get a bunch of warning messages filling your screen.

Trick to do default values passed by reference [ Hide ]
[ Highlight ] [ Text ]
<?
// function declaration
function foo($bar = 'default value here') { ... };
// function calling
foo(); // valid call
foo(&$var); // this, however is consider deprecated in PHP >= 5
?>


Base on the above code:

PHP < 5 complains:

Parse error: parse error, expecting ')' and later on by a fatal error and killing the script execution.

PHP >= 5 complains:

Warning: Call-time pass-by-reference has been deprecated - argument passed by value; If you would like to pass it by reference, modify the declaration of [runtime function name](). If you would like to enable call-time pass-by-reference, you can set allow_call_time_pass_reference to true in your INI file. However, future versions may not support this any longer.
 14 October, 200517 October, 2005 
$ view_blog.php 2009.09.17 18:16:41 $
Lost? | XML/HTML sitemap | Contact
38.107.191.85 , 19 queries , 0.069s
Gzip enabled , CSS compressed , JS compressed
Copyright © 2005-2009 Darren's Outpost