diff options
| author | Levi Bostian <levi.bostian@banno.com> | 2013-11-25 09:42:37 -0600 | 
|---|---|---|
| committer | Levi Bostian <levi.bostian@banno.com> | 2013-11-25 09:42:37 -0600 | 
| commit | af6701904b459b16cf65709cd8c70fd2f5519457 (patch) | |
| tree | 68cb4bf9ead32686f492e68528e9f0761e41c500 /php.html.markdown | |
| parent | df3cc00f5233dac96c0e063d87d3552f493e25f6 (diff) | |
| parent | d24c824d388669181eed99c3e94bb25c2914304a (diff) | |
Fix conflict bash.
Diffstat (limited to 'php.html.markdown')
| -rw-r--r-- | php.html.markdown | 44 | 
1 files changed, 35 insertions, 9 deletions
| diff --git a/php.html.markdown b/php.html.markdown index 083574ee..c3317d59 100644 --- a/php.html.markdown +++ b/php.html.markdown @@ -11,7 +11,7 @@ This document describes PHP 5+.  ```php  <?php // PHP code must be enclosed with <?php tags -// If your php file only contains PHP code, it is best practise +// If your php file only contains PHP code, it is best practice  // to omit the php closing tag.  // Two forward slashes start a one-line comment. @@ -59,6 +59,9 @@ $float = 1.234;  $float = 1.2e3;  $float = 7E-10; +// Delete variable +unset($int1) +  // Arithmetic  $sum        = 1 + 1; // 2  $difference = 2 - 1; // 1 @@ -69,7 +72,7 @@ $quotient   = 2 / 1; // 2  $number = 0;  $number += 1;      // Increment $number by 1  echo $number++;    // Prints 1 (increments after evaluation) -echo ++$number;    // Prints 3 (increments before evalutation) +echo ++$number;    // Prints 3 (increments before evaluation)  $number /= $float; // Divide and assign the quotient to $number  // Strings should be enclosed in single quotes; @@ -104,7 +107,7 @@ echo 'This string ' . 'is concatenated';  /********************************   * Constants   */ -  +  // A constant is defined by using define()  // and can never be changed during runtime! @@ -136,6 +139,11 @@ echo $associative['One']; // prints 1  $array = ['One', 'Two', 'Three'];  echo $array[0]; // => "One" +// Add an element to the end of an array +$array[] = 'Four'; + +// Remove element from array +unset($array[3]);  /********************************   * Output @@ -176,6 +184,11 @@ $y = 0;  echo $x; // => 2  echo $z; // => 0 +// Dumps type and value of variable to stdout +var_dump($z); // prints int(0) + +// Prints variable to stdout in human-readable format +print_r($array); // prints: Array ( [0] => One [1] => Two [2] => Three )  /********************************   * Logic @@ -442,8 +455,10 @@ class MyClass      // Static variables and their visibility      public static $publicStaticVar = 'publicStatic'; -    private static $privateStaticVar = 'privateStatic'; // Accessible within the class only -    protected static $protectedStaticVar = 'protectedStatic'; // Accessible from the class and subclasses +    // Accessible within the class only +    private static $privateStaticVar = 'privateStatic'; +    // Accessible from the class and subclasses +    protected static $protectedStaticVar = 'protectedStatic';      // Properties must declare their visibility      public $property    = 'public'; @@ -463,10 +478,17 @@ class MyClass          print 'MyClass';      } +    //final keyword would make a function unoverridable      final function youCannotOverrideMe()      {      } +/* + * 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()      {          print 'I am static'; @@ -655,10 +677,14 @@ $cls = new SomeOtherNamespace\MyClass();  ## More Information -Visit the [official PHP documentation](http://www.php.net/manual/) for reference and community input. +Visit the [official PHP documentation](http://www.php.net/manual/) for reference +and community input. -If you're interested in up-to-date best practices, visit [PHP The Right Way](http://www.phptherightway.com/). +If you're interested in up-to-date best practices, visit +[PHP The Right Way](http://www.phptherightway.com/). -If you're coming from a language with good package management, check out [Composer](http://getcomposer.org/). +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). +For common standards, visit the PHP Framework Interoperability Group's +[PSR standards](https://github.com/php-fig/fig-standards). | 
