public function testFacade() { $expect = "Build house\nTree grow\nChild born"; $man = new Man(); $result = $man->todo(); $this->assertEquals($result, $expect); }
/** * Function returns book to library and removes it from man * * @param Man $man * @param Book $book */ public function returnBook(Man $man, Book $book) { $book_quality = $this->examinBook($book); if ($book_quality > 80) { $book->setStatus(1); $man->removeBook($book); $this->addBookToAvaible($book); return true; } else { return false; } }
function main($argv) { define('BASE_DIR', getcwd()); $install_path = \Pgit\Lib\Find::install_path(); if (strlen($install_path) > 0) { define('INSTALL_PATH', $install_path); define('WORK_DIR', dirname($install_path)); } $commands = array_slice($argv, 1); if (count($commands) == 0) { echo Man::get('help') . "\n"; exit; } $this->sub($commands); }
static function setDefeat() { self::$status = "Defeat"; }
<?php header('Content-Type:text/html;charset=utf-8'); /* 封装 继承 多态 */ class Man { private $money = 1000; private $gender = '女'; public function showMoney() { return $this->money * 0.2; } } $a = new Man(); //echo $a->money."<br/>";//此时money是私有属性不能随便调用 // $a->name=500; // echo $a->name."<br/>"; echo $a->showMoney(); /* 此时a本来有1000元,但是外部人员却可以擅自修改 所以有时候我们有必要把函数封装起来,不让其他人擅自修改 */
<?php error_reporting(E_ALL); class Man { public $name; public $age; public function getNameAndAge() { echo $this->name . " - " . $this->age . "<br>"; } } $gago = new Man(); $gago->name = "Գագո"; $gago->age = 25; $gago->zdd = 25555; $gago->getNameAndAge(); //echo $gago->name." ՝ "․$gago->age; $zaven = new Man(); $zaven->name = "Զավեն"; echo "<pre>"; var_dump($gago); echo "</pre>"; echo "<pre>"; var_dump($zaven); echo "</pre>";
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <?php echo "hello"; require_once "People.php"; $m = new People(); $m->showInfo(); People::sayHello(); echo People::MAX_MAN_NUM; //for($i=0;$i<10;$i++) { //$m = new People(); //} require_once "Man.php"; $m = new Man(25, "bigwu"); $m->sayHi(); ?> </body> </html>
{ $this->name = $name; } public function setFather(Person $father) { if ($father == "god") { echo "YISUS CRIST"; $this->father = $father; } else { $this->father = $father; } } } // Instantiate the objects $parent = new Man("god"); $son = new Man("Yisus"); $son->setFather($parent); echo "The father of " . $son->name . " is: " . $parent->name; $convertWine = function ($personName) { if ($personName == "Yisus") { return "can"; } else { return "can not"; } }; echo ", and he " . $convertWine("cas") . " convert water into wine\n"; // Some closures $parentName = $parent->name; $moonwalk = function ($name) use($parentName) { if ($name == "Yisus" && $parentName == "god") { return "He can also walk in the water!\n";
<?php /* * Здесь находится ответчик на POST-запросы */ require "Human.php"; require "Man.php"; require "Girl.php"; /* * Если в POST-запросе пришло значение defeat, меняем значение переменной */ if (isset($_POST)) { if (isset($_POST['defeat'])) { if ($_POST['defeat'] == "mans") { Man::setDefeat(); Girl::setWin(); echo "Mans " . Man::getStatus() . "<br>"; echo "Girls " . Girl::getStatus() . "<br>"; } else { Man::setWin(); Girl::setDefeat(); echo "Mans " . Man::getStatus() . "<br>"; echo "Girls " . Girl::getStatus() . "<br>"; } } }