cvs: presentations /slides/intro php53.xml
| From: | Rasmus Lerdorf | Date: | Fri, 15 May 2009 12:00:48 +0000 |
| Subject: | cvs: presentations /slides/intro php53.xml | ||
| Groups: | php.pres | ||
| Request: | Send a blank email to pres+get-1572@lists.php.net to get a copy of this message | ||
rasmus Fri May 15 12:00:48 2009 UTC
Modified files:
/presentations/slides/intro php53.xml
Log:
.
http://cvs.php.net/viewvc.cgi/presentations/slides/intro/php53.xml?r1=1.1&r2=1.2&diff_format=u
Index: presentations/slides/intro/php53.xml
diff -u presentations/slides/intro/php53.xml:1.1 presentations/slides/intro/php53.xml:1.2
--- presentations/slides/intro/php53.xml:1.1 Fri May 15 09:54:34 2009
+++ presentations/slides/intro/php53.xml Fri May 15 12:00:48 2009
@@ -2,7 +2,18 @@
<break lines="1" />
-<example fontsize="1.4em" result='0' title="Defining a
namespace"><![CDATA[<?php
+<example fontsize="1.4em" result='1'
title="Closures"><![CDATA[<?php
+$getClosure = function($v) {
+ return function() use($v) {
+ echo "Hello World: $v!\n";
+ };
+};
+
+$closure = $getClosure(2);
+$closure();
+?>]]></example>
+
+<example fontsize="1.4em" result='0'
title="Namespaces"><![CDATA[<?php
// foo.php
namespace foo;
@@ -21,6 +32,48 @@
<example fontsize="1.4em" hide="1" result='1'
title="Output"><![CDATA[foo\bar]]></example>
+<example fontsize="1.4em" result='1' title="Late Static
Binding"><![CDATA[<?php
+class TestClass {
+ public static function createInstance() {
+ return new static();
+ }
+}
+
+class ChildClass extends TestClass {}
+
+$testClass = TestClass::createInstance();
+$childClass = ChildClass::createInstance();
+
+echo get_class($testClass) . "<br>\n";
+echo get_class($childClass) . "<br>\n";
+?>]]></example>
+
+<example fontsize="1.4em" result="1"
title="get_called_class"><![CDATA[<?php
+abstract class Singleton {
+ private static $instances = array();
+ final public static function getInstance() {
+ $className = get_called_class();
+ if(!isset(self::$instances[$className])) {
+ self::$instances[$className] = new $className();
+ }
+ return self::$instances[$className];
+ }
+}
+
+class foo extends Singleton { }
+class bar extends Singleton { }
+
+$a = foo::getInstance();
+$b = foo::getInstance();
+$c = bar::getInstance();
+
+echo '<pre>';
+var_dump($a);
+var_dump($b);
+var_dump($c);
+echo '</pre>';
+?>]]></example>
+
<example fontsize="1.4em" result='1'
title="NOWDOC"><![CDATA[<?php
echo <<< 'EOB'
NOWDOC is to HEREDOC as single quoted $trings are\n
@@ -47,26 +100,6 @@
}
?>]]></example>
-<example fontsize="1.4em" result="0"
title="get_called_class"><![CDATA[<?php
-abstract class Singleton {
- private static $instances = array();
- final public static function getInstance() {
- $className = get_called_class();
- if(!isset(self::$instances[$className])) {
- self::$instances[$className] = new $className();
- }
- return self::$instances[$className];
- }
-}
-
-class foo extends Singleton { }
-class bar extends Singleton { }
-
-$a = foo::getInstance();
-$b = foo::getInstance();
-$c = bar::getInstance();
-?>]]></example>
-
<example fontsize="1.4em" result="1"
title="DateInterval/DatePeriod"><![CDATA[<?php
$db = new DateTime( '2008-12-31' );
$de = new DateTime( '2009-12-31' );