myol myol - 1 month ago 9
PHP Question

Class extends self

I stumbled across this code today

class FILTER extends self
{
protected static function sanitizeHtml($html)
{
static $parser;

if (!isset($parser)) $parser = new HTMLPurifier;

return $parser->purify($html);
}
}


What does this class gain from extending
self
? Im not quite sure if this ruby example is equivalent or even applicable to PHP.

Answer

That's not valid code, wherever you saw it. It throws up an error.

Fatal error: Cannot use 'self' as class name as it is reserved

You can see an example here: https://eval.in/775753