diff --git a/wip/php.md b/wip/php.md index faa9c70e1..b5df19d02 100644 --- a/wip/php.md +++ b/wip/php.md @@ -28,12 +28,22 @@ See: [PHP tags](http://php.net/manual/en/language.basic-syntax.phptags.php) ```php 20, "banana" => 30 -) +); +echo $fruitsArray['banana']; ``` +Or cast as object + +```php +banana; +``` + ### Inspecting objects ```php @@ -44,3 +54,56 @@ var_dump($object) Prints the contents of a variable for inspection. See: [var_dump](http://php.net/var_dump) + +### Classes + +```php +class Person { + public $name = ''; +} + +$person = new Person(); +$person->name = 'bob'; + +echo $person->name; +``` + +### Getters and setters + +```php +class Person +{ + public $name = ''; + + public function getName() + { + return $this->name; + } + + public function setName($name) + { + $this->name = $name; + return $this; + } +} + +$person = new Person(); +$person->setName('bob'); + +echo $person->getName(); +``` + +### isset vs empty +```php + +$options = [ + 'key' => 'value', + 'blank' => '', + 'nothing' => null, +]; + +var_dump(isset($options['key']), empty($options['key'])); // true, false +var_dump(isset($options['blank']), empty($options['blank'])); // true, true +var_dump(isset($options['nothing']), empty($options['nothing'])); // false, true + +```