Mombu the Php Forum sponsored links

Go Back   Mombu the Php Forum > Php > note 70362 added to language.oop5.visibility
User Name
Password
REGISTER NOW! Mark Forums Read

sponsored links


Reply
 
1 21st December 15:14
florante_navaja
External User
 
Posts: 1
Default note 70362 added to language.oop5.visibility


It is said that the constructor must be declared public.
for whatever reason, it can be declared protected or private!
However, only child classes can make a call to the protected or private parent constructor.
Instantiating the parent class will produce an error.
In the same manner, a protected __destruct in the parent class is possible, but *must not* be private.

Here's the snippet:

<?php
class Visibility
{
public function pubFunc() {
echo 'pubFunc called';
}
protected function protFunc() {
echo 'protFunc called ';
}
private function privFunc() {
echo 'privFunc called';
}
function privAccessor() {
privFunc();
}

/*alternate these next two lines */

//private function __construct() {
protected function __construct() {
echo 'Visibility constructor called';
}

// private function __destruct() //fails!
protected function __destruct() { //ok!
echo 'Visibility destructor called';
}
}

class ChildVisibility extends Visibility
{
public function callProtFunc() {
parent:rotFunc();
}

public function __construct() {
parent::__construct();
echo 'ChildVisibility constructor called';
}

public function __destruct() {
echo 'ChildVisibility destructor called';
parent::__destruct();
}
}

$oCV = new ChildVisibility();
$oCV->callProtFunc();

?>
Here's what i got:

Visibility constructor called
ChildVisibility constructor called
protFunc called
ChildVisibility destructor called
Visibility destructor called
----
Server IP: 66.163.161.117
Probable Submitter: 218.219.13.70 (proxied: unknown)
----
Manual Page -- http://www.php.net/manual/en/language.oop5.visibility.php
Edit -- https://master.php.net/note/edit/70362
Del: integrated -- https://master.php.net/note/delete/70362/integrated
Del: useless -- https://master.php.net/note/delete/70362/useless
Del: bad code -- https://master.php.net/note/delete/70362/bad+code
Del: spam -- https://master.php.net/note/delete/70362/spam
Del: non-english -- https://master.php.net/note/delete/70362/non-english
Del: in docs -- https://master.php.net/note/delete/70362/in+docs
Del: other reasons-- https://master.php.net/note/delete/70362
Reject -- https://master.php.net/note/reject/70362
Search -- https://master.php.net/manage/user-notes.php
  Reply With Quote


  sponsored links


2 21st December 15:21
bobby
External User
 
Posts: 1
Default note 70362 rejected from language.oop5.visibility by bobby


Note Submitter: florante_navaja at yahoo dot com

----

It is said that the constructor must be declared public.
for whatever reason, it can be declared protected or private!
However, only child classes can make a call to the protected or private parent constructor.
Instantiating the parent class will produce an error.
In the same manner, a protected __destruct in the parent class is possible, but *must not* be private.

Here's the snippet:

<?php
class Visibility
{
public function pubFunc() {
echo 'pubFunc called';
}
protected function protFunc() {
echo 'protFunc called ';
}
private function privFunc() {
echo 'privFunc called';
}
function privAccessor() {
privFunc();
}

/*alternate these next two lines */

//private function __construct() {
protected function __construct() {
echo 'Visibility constructor called';
}

// private function __destruct() //fails!
protected function __destruct() { //ok!
echo 'Visibility destructor called';
}
}

class ChildVisibility extends Visibility
{
public function callProtFunc() {
parent:rotFunc();
}

public function __construct() {
parent::__construct();
echo 'ChildVisibility constructor called';
}

public function __destruct() {
echo 'ChildVisibility destructor called';
parent::__destruct();
}
}

$oCV = new ChildVisibility();
$oCV->callProtFunc();

?>
Here's what i got:

Visibility constructor called
ChildVisibility constructor called
protFunc called
ChildVisibility destructor called
Visibility destructor called
  Reply With Quote


  sponsored links


Reply


Thread Tools
Display Modes




Copyright 2006 SmartyDevil.com - Dies Mies Jeschet Boenedoesef Douvema Enitemaus -
666