<?
class Post
{
public function __construct()
{
echo $this->getKeywords(); echo "\r\n";
echo $this->getDescription(); echo "\r\n";
echo $this->getTitle(); echo "\r\n";
}
public function getKeywords()
{
return 'POST:keywords';
}
protected function getDescription()
{
return 'POST:description';
}
private function getTitle()
{
return 'POST:title';
}
}
class News extends Post
{
public function __construct()
{
parent::__construct();
}
public function getKeywords()
{
return 'News:keywords';
}
protected function getDescription()
{
return 'News:description';
}
private function getTitle()
{
return 'News:title';
}
}
//1 случай
$Object = new News();
//2 случай
echo $Object->getKeywords(); echo "\r\n";
echo $Object->getTitle(); echo "\r\n";
echo $Object->getDescription(); echo "\r\n";
Output for 8.0.13
News:keywords
News:description
POST:title
News:keywords
Fatal error: Uncaught Error: Call to private method News::getTitle() from global scope in /in/rqeDA:53
Stack trace:
#0 {main}
thrown in /in/rqeDA on line 53
Process exited with code 255.
News:keywords
News:description
POST:title
News:keywords
Fatal error: Uncaught Error: Call to private method News::getTitle() from context '' in /in/rqeDA:53
Stack trace:
#0 {main}
thrown in /in/rqeDA on line 53
Process exited with code 255.
Output for 5.5.24 - 5.5.35, 5.6.8 - 5.6.28
News:keywords
News:description
POST:title
News:keywords
Fatal error: Call to private method News::getTitle() from context '' in /in/rqeDA on line 53
Process exited with code 255.