Which keyword should be used in the line marked with "KEYWORD" instead of "self" to make this code work as intended?

Posted by: Pdfprep Category: 200-710 Tags: , ,

Consider the following code.

Which keyword should be used in the line marked with "KEYWORD" instead of "self" to make this code work as intended?

abstract class Base {

protected function _ construct() {

}

public static function create() {

return new self(); // KEYWORD

}

abstract function action();

}

class Item extends Base {

public function action() {

echo __ CLASS __ ;

}

}

$item = Item::create();

$item->action(); // outputs "Item"

Consider the following code.

Which keyword should be used in the line marked with "KEYWORD" instead of "self" to make this code work as intended?

Answer: static

Leave a Reply

Your email address will not be published.