note 120028 added to language.oop5.abstract

From: Date: Wed, 12 Oct 2016 13:46:41 +0000
Subject: note 120028 added to language.oop5.abstract
Groups: php.notes 
Request: Send a blank email to php-notes+get-206854@lists.php.net to get a copy of this message
A snippet of code to help you understand a bit more about properties inside abstract classes: <?php abstract class anotherAbsClass { // Define and set a static property static $stProp = 'qwerty'; // We can still use it directly by the static way // Define and set a protected property protected $prProp = 'walrus'; // It is useless to set any other level of visibility for non-static variables of an abstract class. // We cannot access to a private property even inside a declared method of an abstract class because we cannot call that method in the object context. // Implementation of a common method protected function callMe() { echo 'On call: ' . $this->prProp . PHP_EOL; } // Declaration of some abstract methods abstract protected function abc($arg1, $arg2); abstract public function getJunk($arg1, $arg2, $arg3, $junkCollector = true); // Note: we cannot omit an optional value without getting error if it has already been declared by an abstract class } class someChildClass extends anotherAbsClass { function __construct() { echo $this->callMe() . PHP_EOL; // now we get the protected property $prProp inhereted from within the abstract class } // There must be implementation of the declared functions abc and getJunk below protected function abc($val1, $val) { // do something } function getJunk($val1, $val2, $val3, $b = false) { // optional value is neccessary, because it has been declared above // do something } } echo anotherAbsClass::$stProp; // qwerty $objTest = new someChildClass; // On call: walrus ?> ---- Server IP: 72.52.91.14 Probable Submitter: 95.59.244.247 ---- Manual Page -- http://php.net/manual/en/language.oop5.abstract.php Edit -- https://master.php.net/note/edit/120028 Del: integrated -- https://master.php.net/note/delete/120028/integrated Del: useless -- https://master.php.net/note/delete/120028/useless Del: bad code -- https://master.php.net/note/delete/120028/bad+code Del: spam -- https://master.php.net/note/delete/120028/spam Del: non-english -- https://master.php.net/note/delete/120028/non-english Del: in docs -- https://master.php.net/note/delete/120028/in+docs Del: other reasons-- https://master.php.net/note/delete/120028 Reject -- https://master.php.net/note/reject/120028 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#206854) next »