101
reputation
3

Sworrub Wehttam

<?php
class Head
{
    public $mouth;

    private function __construct()
    {
        $this->mouth = new Mouth();
    }

    private function hurts()
    {
        return [
            'my ' . get_class($this) => 'ouch!'
        ];
    }

    public function recursive($painThreshold = 10)
    {
        $painThresholdMet = !$painThreshold;
        if ($painThresholdMet) {
            return $this->mouth;
        }
        $func = __FUNCTION__;
        $pain = $this->hurts()['my Head'];
        $this->mouth->speech .= "$func functions hurt, $pain\n";
        return $this->$func($painThreshold - 1);
    }
}

class Mouth
{
    public $speech = '';

    public function __toString()
    {
        return $this->speech;
    }
}

$head = new Head();
$head->recursive();
echo $head->mouth;
1
answer
0
questions
0
people reached
  • Lancaster, United Kingdom
  • Member for 3 years
  • 0 profile views
  • Last seen Oct 11 '17 at 7:28

Top tags (2)

Score 0
Posts 1
Score 0
Posts 1

Top posts (1)

Badges (3)

Gold

Silver

Bronze

3

Rarest