note 101664 rejected from language.oop5.visibility by danbrown
| From: | danbrown@php.net | Date: | Mon, 03 Jan 2011 17:18:34 +0000 |
| Subject: | note 101664 rejected from language.oop5.visibility by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-175412@lists.php.net to get a copy of this message | ||
Note Submitter: acetox94 at gmx dot de
----
<?php
abstract class Foo
{
abstract protected function __construct();
}
class Bar extends Foo
{
public function __construct()
{
}
}
$obj_bar = new Bar();
?>
Works...
<?php
abstract class Foo
{
abstract protected function __construct();
}
class Bar extends Foo
{
protected function __construct()
{
}
}
$obj_bar = new Bar();
?>
Outputs: "Fatal error: Call to protected Bar::__construct() from invalid context" - as
expected, because __construct() has to be public in this case..
But:
<?php
abstract class Foo
{
abstract protected function __construct();
}
class Bar extends Foo
{
private function __construct()
{
}
}
$obj_bar = new Bar();
?>
Ouputs:"Fatal error: Access level to Bar::__construct() must be protected (as in class Foo) or
weaker"
I think "private" is weaker than "protected", isn't it?
And: Should the concrete Class "Bar", wich extends "Foo" not have exactly the
same visibility of __construct() as in "Foo"?