The slides from my talk, introducing PHP 5.4 are now available and can be downloaded here: http://ilia.ws/files/nena_php54.pdf.
Thanks for all the attendees for being a wonderful audience, especially those asking many great questions.
P.S. If you've seen the talk please don't forget to leave feedback at Joind.in.
The slides from my presentation at PHP-GTA about the Hidden Features of PHP is now available online and can be downloaded here: http://ilia.ws/files/php-toronto_hidden_features.pdf. Hopefully everyone in attendance learned something new about PHP and many thanks to all the people who had asked questions helped make the discussion that much more interesting.
For our database connections we PDO at work and we've extended the class with PHP to offer some other convenience functionality and wrappers. One of the things I wanted to do recently is allow the constructor of the PDO class to fail-over to our backup database connection pool in the event the primary was not available. The idea was to do something along the lines of:
[php]
class DB extends PDO {
public function __construct($dsn, $login, $pass, $backup_dsn) {
try {
parent::construct($dsn, $login, $pass);
} catch (Exception $e) {
parent::construct($backup_dsn, $login, $pass);
}
}
}
[/php]
Essentially the code would call the PDO's own constructor, if it would fail, an exception would be raised, which would then be caught by the exception handler that will attempt to connect to the backup database connection pool. Unfortunately this simple solution does not work, the reason being, is that when PDO's constructor fails to connect, it destroys the object. Which means any attempts to use or access the objec...
At Confoo I had an interesting conversation with Guilherme Blanco regarding the fact that in Doctrine 2 they had a performance issue due to usage of array_key_exists() and how it was significantly slower than isset(). His anecdotal example was that doing isset() took 0.5 seconds, while array_key_exists() for the same operation took 5 seconds!
That seemed wrong, given that array_key_exists() simply does a hash table look-up, to determine if the array key exists and the only speed difference would be due to the fact that isset() is a language construct and does not have the overhead of function & parameter processing. So, I've decided to do a quick benchmark using a 5,000 element array.
[php]
$arr = array();
$fp = fopen("/usr/share/dict/words", "r");
while ($i < 5000 && ($w = fgets($fp))) {
$arr[trim($w)] = ++$i;
}
$s = microtime(1);
for ($i = 0; $i < 100000; $i++) {
isset($arr['abracadabra']);
}
$e = microtime(1);
echo "Isset: ".($e - $s)."\n";
$s = microtime(1);
for ($i = 0; $i < 100000; $i++) {...
My slides from the Confoo presentation on PHP 5.4 are up and can be viewed/downloaded from here:
http://ilia.ws/files/confoo_php54.pdf
I look forward to everyone's feedback either on this blog or via Joind.in.
And in case you didn't know, PHP 5.4 was released yesterday!
[Update March 3, 2012]
Based on great suggestion from Rasmus, I've updated the charset slide to clarify that the change introduced in 5.4 relates to the default charset used by internal entities functions (htmlspecialchars, htmlentities, etc...) and updating the default_charset INI is one of the changes you may need to do to account for this change.