main.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
class Woodchuck {

  protected $wood;

  public function __construct($wood) {
    $this->wood = $wood;
  }

  public function canChuckWood() {
    return $this->wood ? true : false;
  }

  public function getWoodAmmount() {
    return $this->canChuckWood() ? $this->wood : 0;
  }

}

$woodchuck1 = new Woodchuck(0);
$woodchuck2 = new Woodchuck(10);
 
var_dump($woodchuck1->canChuckWood()); // has no wood to chuck, woodchuck cannot chuck
var_dump($woodchuck2->canChuckWood()); // woodchuck2 can chuck wood

var_dump($woodchuck2->getWoodAmmount()); // woodchuck2 chucks as much wood as possible
PHP 7.0.8 (cli) (built: Jun 23 2016 23:39:14) ( NTS ) Copyright (c) 1997-2016 The PHP Group Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies