Oct/090
Fatal error: Call to undefined function: curl_init in php
For some reason, my workstation with Ubuntu 9.04, php5, apache2 and php5-curl install was giving me the curl package not installed message. Well, it turns out that for some reason, my default /etc/php5/apache2/php.ini had the extension directory pointing to /usr/lib/php5/ext/ while all the extensions were in /usr/lib/php5/20060613/
I was trying to figure out why I am not seeing curl.so in the ext directory after I have apt-get installed and removed php5-curl many times. Solution is usually very simple.
Oct/060
Beware duplicate mail()’s in PHP/Firefox
Strangely, invoking the PHP SMTP mail() function after outputting any HTML within a PHP page will cause Firefox to intepret the PHP command twice, thereby sending out 2 duplicate emails. This was happening using PHP5, FF1.5, and Windows IIS6. The issue is fixed by simply placing the mail() command as the first part of any script, before any headers or output are called. I cannot ascertain yet why this is occurring. Any ideas, anyone?
Jun/0644
Fatal error: Cannot use string offset as an array in …
PHP5 Error message that is caused by attempting to assign a value to an array element of a variable that is declared as a string.
Example that generates error:
$foo=’bar’;
$foo[0]=’bar’;
Get error message Fatal error: Cannot use string offset as an array in …
Explanation
$foo was declared as a string in $foo=’bar’.
$foo[0] is trying to append an element onto a string variable.
Example that does not generate error:
$foo[0]=’bar’;
$foo=’bar’;
Does NOT generate error.
Explanation
$foo[0]=’bar’ instantiates variable $foo as array since it has not been instantiated. Then assigns ‘bar’ to element $foo[0].
$foo=’bar’ implicitly re-declares $foo as a string and assigns ‘bar’ to it.
Example that does not generate error:
$foo=’bar’;
$foo=array();
$foo[0]=’bar’;
Explanation
$foo=’bar’ implicitly declares $foo as a string variable then assigns ‘bar’ as the value.
$foo=array() explicitly re-declares $foo as an array.
$foo[0]=’bar’ can now be executed as $foo is declared as an array.
Let me know if this helped you or if I am not clear on anything. Thanks.