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.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents