Sworrub Wehttam
  • Lancaster, United Kingdom
  • Member for 4 years, 8 months
Stats
101
reputation
0
reached
0
answers
0
questions
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;
This user doesn’t have any gold badges yet.
This user doesn’t have any silver badges yet.
2
bronze badges

Keeping a low profile.

This user hasn't posted yet.