Inline class definition no loading required
suggest change// zoo.php
class Animal {
public function eats($food) {
echo "Yum, $food!";
}
}
$animal = new Animal();
$animal->eats('meat');
PHP compiles a file before running it, so new Animal may appear before or after class Animal in that same file. A class declared in another file is unavailable until that file is loaded.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents