diff options
author | Sean Corrales <scorrales@gmail.com> | 2015-10-05 09:50:44 -0500 |
---|---|---|
committer | Sean Corrales <scorrales@gmail.com> | 2015-10-05 09:50:44 -0500 |
commit | fe5157d36f4b508479edaa214e097f65e7ba26e1 (patch) | |
tree | e6a3f377ba4ed7735bbcf3c2908082b811168e9e /php.html.markdown | |
parent | a743c831a07f5e846051b156152fe8e6ddcfb097 (diff) | |
parent | e57fb68756ec6f4242ad04c359f7796606b52a42 (diff) |
Merge pull request #1 from adambard/master
Merging changes from source branch
Diffstat (limited to 'php.html.markdown')
-rw-r--r-- | php.html.markdown | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/php.html.markdown b/php.html.markdown index 2d4565e0..93066284 100644 --- a/php.html.markdown +++ b/php.html.markdown @@ -215,6 +215,14 @@ assert($a !== $d); assert(1 === '1'); assert(1 !== '1'); +// spaceship operator since PHP 7 +$a = 100; +$b = 1000; + +echo $a <=> $a; // 0 since they are equal +echo $a <=> $b; // -1 since $a < $b +echo $b <=> $a; // 1 since $b > $a + // Variables can be converted between types, depending on their usage. $integer = 1; @@ -264,6 +272,18 @@ if (false) { // ternary operator print (false ? 'Does not get printed' : 'Does'); +// ternary shortcut operator since PHP 5.3 +// equivalent of "$x ? $x : 'Does'"" +$x = false; +print($x ?: 'Does'); + +// null coalesce operator since php 7 +$a = null; +$b = 'Does print'; +echo $a ?? 'a is not set'; // prints 'a is not set' +echo $b ?? 'b is not set'; // prints 'Does print' + + $x = 0; if ($x === '0') { print 'Does not print'; @@ -487,7 +507,7 @@ class MyClass * Declaring class properties or methods as static makes them accessible without * needing an instantiation of the class. A property declared as static can not * be accessed with an instantiated class object (though a static method can). -*/ + */ public static function myStaticMethod() { @@ -495,7 +515,9 @@ class MyClass } } +// Class constants can always be accessed statically echo MyClass::MY_CONST; // Outputs 'value'; + echo MyClass::$staticVar; // Outputs 'static'; MyClass::myStaticMethod(); // Outputs 'I am static'; @@ -687,4 +709,4 @@ If you're coming from a language with good package management, check out [Composer](http://getcomposer.org/). For common standards, visit the PHP Framework Interoperability Group's -[PSR standards](https://github.com/php-fig/fig-standards). +[PSR standards](https://github.com/php-fig/fig-standards).
\ No newline at end of file |