Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 
avatar of Sworrub Wehttam

Sworrub Wehttam

Sworrub Wehttam has asked 0 questions and find answers to 3 problems.

Stats

45
EtPoint
9
Vote count
0
questions
3
answers

About

<?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;