note 115704 added to language.oop5.abstract
| From: | sam at righthandedmonkey dot com | Date: | Thu, 11 Sep 2014 15:43:54 +0000 |
| Subject: | note 115704 added to language.oop5.abstract | ||
| Groups: | php.notes php.notes | ||
| Request: | Send a blank email to php-notes+get-200414@lists.php.net to get a copy of this message | ||
Please note order or positioning of the classes in your code can affect the interpreter and can
cause a Fatal error: Class 'YourClass' not found if there are multiple levels of
abstraction out of order. For example:
<?php
abstract class horse extends animal {
public function get_breed() { return "Jersey"; }
}
class cart extends horse {
public function get_breed() { return "Wood"; }
}
abstract class animal {
public abstract function get_breed();
}
$cart = new cart();
print($cart->get_breed());
?>
this outputs:
Wood
However, if you put the cart before the abstract horse (literally):
<?php
class cart extends horse {
public function get_breed() { return "Wood"; }
}
abstract class horse extends animal {
public function get_breed() { return "Jersey"; }
}
abstract class animal {
public abstract function get_breed();
}
$cart = new cart();
print($cart->get_breed());
?>
this throws an error:
Fatal error: Class 'horse' not found
So, when using multiple levels of abstraction, be careful of the positioning of the classes within
the source code - and don't put the cart before the abstract horse.
----
Server IP: 72.52.91.14
Probable Submitter: 73.33.242.72
----
Manual Page -- http://php.net/manual/en/language.oop5.abstract.php
Edit -- https://master.php.net/note/edit/115704
Del: integrated -- https://master.php.net/note/delete/115704/integrated
Del: useless -- https://master.php.net/note/delete/115704/useless
Del: bad code -- https://master.php.net/note/delete/115704/bad+code
Del: spam -- https://master.php.net/note/delete/115704/spam
Del: non-english -- https://master.php.net/note/delete/115704/non-english
Del: in docs -- https://master.php.net/note/delete/115704/in+docs
Del: other reasons-- https://master.php.net/note/delete/115704
Reject -- https://master.php.net/note/reject/115704
Search -- https://master.php.net/manage/user-notes.php