public function testCat() { $cat = new Cat("Thelma"); $this->assertEquals("Thelma", $cat->getName()); $this->assertEquals("Thelma the Cat", (string) $cat); $cat->setName("Alice"); $this->assertEquals("Alice", $cat->getName()); $this->assertEquals("Alice the Cat", (string) $cat); }
public function testGiveCatBirthAgeAndName() { $name = 'Garfield'; $age = 0; $cat = new Cat(compact('name', 'age')); $this->assertEquals($name, $cat->getName()); $this->assertEquals($age, $cat->getAge()); }
<?php function __autoload($class_name) { $name = $class_name . ".php"; if (file_exists($name)) { require_once $name; } else { echo "Class not found"; } } $cat = new Cat("maca", 23); var_dump($cat->getName()); echo $cat::$counter; $cat->talk();
<?php include 'autoload.php'; $cat = new Cat('garfield'); echo $cat->getName() === 'garfield'; echo $cat->meow() === 'Cat garfield is saying meow';
* Created by PhpStorm. * User: HP * Date: 21.12.2015 * Time: 23:09 */ ini_set('display_errors', 1); error_reporting(E_ALL); class Animal { public $name; public function __construct($name) { $this->name = $name; } public function getName() { echo $this->name; } } class Cat extends Animal { function meow() { echo "Cat {$this->name} is saying meow"; // getName() - это метод, а не свойство, поэтому нужны скобки } } $cat = new Cat('Garfield'); $cat->getName(); echo '<br>'; $cat->meow();
function displayInfo(Cat $n) { echo $n->getName() . " is a " . $n->getColor() . " " . $n->getBreed() . " cat.</br> </br>"; }