22. Mais leur comportement est identique class Foo { public function maFonction($arg1) { } } $a = new Foo; class Foo { function maFonction($arg1) { } } $a = &new Foo;
23.
24.
25.
26. PHP5 introduit "public", "protected", "private" class Foo { var $a; // ok, pas de problème, sera publique function bar(); // idem : sera publique } class Foo { var $a; function bar(); }
32. Petits pièges du modèle objet All right ! False true false Fatal error Fatal error false true class Foo { public function bar() { $this = new Something; } } class Foo { public $foo; } $foo1 = new Foo; $foo2 = new Foo; $foo1->foo = $foo2; $foo2->foo = $foo1; var_dump($foo1 == $foo2); class Foo { } $foo = new Foo; var_dump(empty($foo)); var_dump((bool)$foo);
33.
34.
35. E_ALL n'inclut pas E_STRICT class Foo { public function maFonction($arg1) { } } class Bar extends Foo { public function maFonction($arg1, $arg2) { } } Strict standards: Declaration of Bar::maFonction() should be compatible with that of Foo::maFonction() in /media/data/www/labo/newfile.php on line 10 $a = &new Foo; Strict standards : ... ... class Foo { public function hello() { } } Foo::hello(); abstract static function bar();
38. Envoyée lors de problèmes de typage d'arguments Class Foo { public function maFonction( Linux $arg1) { } public static function errorHandler($errno, $errstr) { echo "erreur attrapée : $errstr"; } } set_error_handler(array('Foo, 'errorHandler')); $a = new Anaska; $a->maFonction("Autre chose qu'un objet Linux"); erreur attrapée : Argument 1 passed to Foo::maFonction() must be an instance of Linux, string given, called in /media/data/www/labo/newfile.php on line 15 and defined ...
39.
40.
41. Activez-le pour vous en rendre compte // php.ini error_reporting = E_ALL | E_STRICT
42.
43. Je peux aussi utiliser temporairement le mode de compatibilité
60. Voyons un peu les différences ext/MySQL <-> ext/MySQLi
61.
62. La connexion est implicite, les fonctions réutilisent la dernière mysql_connect('localhost', 'julien', 'anaska'); mysql_select_db('membres'); $age = 29; $sql = mysql_query("SELECT nom, prenom FROM membres WHERE age < $age"); while ($result = mysql_fetch_array($sql)) { printf("%s %s a %d ans " . PHP_EOL, $result['nom'], $result['prenom'], $age); } mysql_close();