summaryrefslogtreecommitdiffhomepage
path: root/php.html.markdown
diff options
context:
space:
mode:
authorLevi Bostian <levi.bostian@gmail.com>2015-10-18 12:03:02 -0500
committerLevi Bostian <levi.bostian@gmail.com>2015-10-18 12:03:02 -0500
commit6e3c5d677f2f6bae31634673daf6170e22aad24f (patch)
treee9f141ef3fef68550cb9ec175d6ab655de9d7c81 /php.html.markdown
parent5338b9ac0aaecf34dc7eea58798daaf852bd575d (diff)
parent6c14f507c24524de4815cac05b55bf9a56e7cd06 (diff)
Merge pull request #1544 from Glutnix/php-late-static-binding
[php/en] Adds late static binding
Diffstat (limited to 'php.html.markdown')
-rw-r--r--php.html.markdown49
1 files changed, 43 insertions, 6 deletions
diff --git a/php.html.markdown b/php.html.markdown
index c53522cd..5bc2ddce 100644
--- a/php.html.markdown
+++ b/php.html.markdown
@@ -712,6 +712,43 @@ use My\Namespace as SomeOtherNamespace;
$cls = new SomeOtherNamespace\MyClass();
+
+/**********************
+* Late Static Binding
+*
+* /
+
+class ParentClass {
+ public static function who() {
+ echo "I'm a " . __CLASS__ . "\n";
+ }
+ public static function test() {
+ // self references the class the method is defined within
+ self::who();
+ // static references the class the method was invoked on
+ static::who();
+ }
+}
+
+ParentClass::test();
+/*
+I'm a ParentClass
+I'm a ParentClass
+*/
+
+class ChildClass extends ParentClass {
+ public static function who() {
+ echo "But I'm " . __CLASS__ . "\n";
+ }
+}
+
+ChildClass::test();
+/*
+I'm a ParentClass
+But I'm ChildClass
+*/
+
+
/**********************
* Error Handling
*
@@ -727,9 +764,9 @@ try {
// When using try catch blocks in a namespaced enviroment use the following
-try {
+try {
// Do something
-} catch (\Exception $e) {
+} catch (\Exception $e) {
// Handle exception
}
@@ -738,13 +775,13 @@ try {
class MyException extends Exception {}
try {
-
- $condition = true;
-
+
+ $condition = true;
+
if ($condition) {
throw new MyException('Something just happend');
}
-
+
} catch (MyException $e) {
// Handle my exception
}