Skip to main content
Sworrub Wehttam's user avatar
Sworrub Wehttam's user avatar
Sworrub Wehttam's user avatar
Sworrub Wehttam
  • Member for 7 years, 11 months
  • Last seen more than 4 years ago
  • Lancaster, United Kingdom
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;
Badges
This user doesn’t have any gold badges yet.
This user doesn’t have any silver badges yet.
2
bronze badges
Posts

This user hasn’t posted yet.