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); }
function beforeroute() { //list of categories $cats = new Cat($this->db); $this->f3->set('cs', $cats->all()); //item count (menu) $items = new Item($this->db); $nb = $items->itemcount(); $this->f3->set('cgall', $nb); //category menu $cgs = new CatGroup($this->db); $this->f3->set('cgs', $cgs->all()); }
/** * */ public function testWrite_WriteObjects_ObjectsWritten() { $batchSizes = array(10, 30, 100, 300); foreach ($batchSizes as $size) { $owners = array(); $dogs = array(); $cats = array(); $writer = new \BatchedWriter($size); for ($i = 0; $i < 100; $i++) { $owner = new Human(); $owner->Name = 'Human ' . $i; $dog = new Dog(); $dog->Name = 'Dog ' . $i; $cat = new Cat(); $cat->Name = 'Cat ' . $i; $owner->onAfterExistsCallback(function ($owner) use($dog, $writer) { $dog->OwnerID = $owner->ID; $writer->write($dog); }); $dog->onAfterExistsCallback(function ($dog) use($cat, $writer) { $cat->EnemyID = $dog->ID; $writer->write($cat); }); $owners[] = $owner; $dogs[] = $dog; $cats[] = $cat; } // writes dogs first time $writer->write($dogs); // dogs written again from owner callback $writer->write($owners); $writer->finish(); $owners = Human::get(); $dogs = Dog::get(); $cats = Cat::get(); $this->assertEquals(100, $owners->Count()); $this->assertEquals(100, $dogs->Count()); $this->assertEquals(100, $cats->Count()); for ($i = 0; $i < 100; $i++) { $owner = $owners[$i]; $dog = $dogs[$i]; $cat = $cats[$i]; $this->assertEquals($owner->ID, $dog->OwnerID); $this->assertEquals($dog->ID, $cat->EnemyID); } $writer->delete($owners); $writer->delete($dogs); $writer->delete($cats); $writer->finish(); $this->assertEquals(0, Human::get()->Count()); $this->assertEquals(0, Dog::get()->Count()); $this->assertEquals(0, Cat::get()->Count()); } }
<?php require_once "Animal.php"; require_once "Cat.php"; /** * @author Gutsulyak Vadim <*****@*****.**> */ $animal = new Animal("green"); $animal->sayHello(); $cat = new Cat("white"); $cat->sayHello(); $cat->sayMeow();
} else { echo $this->name . " is fully fed!"; echo "<br>"; } } public function howOld() { echo $this->name . " is " . $this->age . " years old."; echo "<br>"; echo $this->name . " is " . $this->age . " cat years old!"; echo "<br>"; } } $cat1 = new Cat("Little Buddy", 2, 8); $cat2 = new Cat("Sneaky Pete", 0, 2); $cat3 = new Cat("whiskers", 1, 2); $cat1->howOld(); $cat1->feedCat(6); $cat3->howOld(); echo $cat2->name; echo "<br>"; echo "TESTING!!!!"; $student1 = new Student('Harry', 'Potter', 17); $student2 = new Student('Charlie', 'Brown', 16); $student3 = new Student('Gary', 'Coleman', 15); echo $student1->firstName; echo "<br>"; echo $student1->lastName; echo "<br>"; echo $student1->age; echo "<br>";
echo "<br>"; } } public function howOld() { echo $this->name . " is " . $this->age . " years old."; echo "<br>"; echo $this->name . " is " . $this->age . " cat years old!"; echo "<br>"; } } $cat1 = new Cat("Little Buddy", 2, 8); $cat2 = new Cat("Sneaky Pete", 0, 2); $cat3 = new Cat("Jim", 1, 3); $cat4 = new Cat("Tom", 2, 5); $cat5 = new Cat("Kit", 120, 500); $cat1->howOld(); $cat1->feedCat(6); $cat3->howOld(); $cat5->howOld(); echo $cat2->name; echo "<br>"; // =========== NEW CLASS ========== class Car { public $brand; public $price; public function __construct($_brand, $_price) { $this->brand = $_brand; $this->price = $_price;
<?php /** * Created by PhpStorm. * User: ET * Date: 6/26/2015 * Time: 5:34 PM */ include 'Dog.php'; include 'Cat.php'; echo Pet::getCount() . "<-Total Pet object<br>"; // 0 $dog = new Dog('Satchel'); echo Pet::getCount() . "<-Total Pet object<br>"; // 1 $cat = new Cat('Bucky'); echo Pet::getCount() . "<-Total Pet object<br>"; // 2 $dog->eat(); $cat->eat(); $dog->sleep(); $cat->sleep(); $dog->play(); $cat->play(); echo "Unset dog object<br>"; unset($dog); echo Pet::getCount() . " Pet instance left<br>"; // 1 echo "Unset cat instance<br>"; unset($cat); echo Pet::getCount() . " Pet instance left<br>";
<?php include 'Cat.php'; $cat1 = new Cat(); $cat1->setColor("black"); $cat1->setName("Zoe"); $cat1->setBreed("Siamese "); $myCats[] = $cat1; $cat2 = new Cat(); $cat2->setColor("orange"); $cat2->setName("Garfield"); $cat2->setBreed("Tabby "); $myCats[] = $cat2; $cat3 = new Cat(); $cat3->setColor("tabby"); $cat3->setName("Fluffy"); $cat3->setBreed("catType3 "); $myCats[] = $cat3; $count = 0; catCount($myCats, $count); echo "the count for is " . $count . "<br>"; for ($i = 0; $i < 3; $i++) { displayCatInfo($myCats[$i]); } function catCount($cats, &$num) { for ($i = 0; $i < 2; $i++) { if ($cats[$i]->getColor() == "orange") { $num++; } }
var_dump($valores); die; print_r($GLOBALS); die; echo "<form action='closure.php' method='POST'>"; echo "<input type='text' name='a'>"; echo "<input type='text' name='b'>"; echo "<input type='text' name='c'>"; echo "<input type='text' name='d'>"; echo "<input type='text' name='e'>"; ?> <input type='submit' name='action' value='Submit'> <?php echo "</form>"; echo file_get_contents("php://input"); die; class Cat { public $sound = "meow"; function meow() { echo $this->sound . "<br>" . PHP_EOL; } } $showSound = function () { echo "Sound is " . $this->sound; }; $lenny = new Cat(); //$showSound->bindTo($lenny); $lenny->meow();
switch ($key) { case "Libelle": $three = $txt; break; case "Categorie": $two = $txt; break; case "Style": $one = $txt; break; } } //==============fill first record===============-------------------------------------- //trim space and comma $pathN = yakcatPathN($one); $categorie = new Cat($one, $one, $pathN, 1, '', $status); $succes = $categorie->saveToMongo($level = 1); //================fill record two====================================== $title2 = $two; $path2 = $one . ", " . $two; $pathN2 = $pathN . "#" . yakcatPathN($title2); echo "<br>" . $pathN; $categorie->setAncestors($one, $pathN); $categorie->setParent($one, $pathN); $categorie->title = $title2; $categorie->path = $path2; $categorie->pathN = $pathN2; $categorie->level = 2; $succes = $categorie->saveToMongo($level = 2); //exit; //insert db results for ID--here---------------------------
echo $this->name . " needs more food than that!"; echo "<br>"; } else { echo $this->name . " is fully fed!"; echo "<br>"; } } public function howOld() { echo $this->name . " is " . $this->age . " years old."; echo "<br>"; echo $this->name . " is " . $this->age . " cat years old!"; echo "<br>"; } } $cat1 = new Cat("Little Buddy", 2, 8); $cat2 = new Cat("Sneaky Pete", 0, 2); $cat1->howOld(); $cat1->feedCat(6); echo $cat2->name; echo "<br>"; ?> </body> </html>
public function search() { $busq = Input::get('busq'); $title = "Busqueda: " . $busq; $cat = Cat::where('deleted', '=', 0)->get(array('categorias.id', 'categorias.cat_nomb')); $subcat = array(); foreach ($cat as $c) { $aux = SubCat::where('cat_id', '=', $c->id)->where('deleted', '=', 0)->get(); $subcat[$c->id] = $aux->toArray(); } $art = DB::select("SELECT DISTINCT `item`.`id`,\t\n\t\t\t\t\t\t\t\t\t\t `item`.`item_nomb`,\n\t\t\t\t\t\t\t\t\t\t `item`.`item_cod`,\n\t\t\t\t\t\t\t\t\t\t `item`.`item_stock`,\n\t\t\t\t\t\t\t\t\t\t `item`.`item_precio`,\n\t\t\t\t\t\t\t\t\t\t `m`.`id` AS misc_id,\n\t\t\t\t\t\t\t\t\t\t `i`.`image`\n\t\t\tFROM `item` \n\t\t\tLEFT JOIN `miscelanias` AS m ON `m`.`item_id` = `item`.`id` \n\t\t\tLEFT JOIN `images` \t AS i ON `i`.`misc_id` = `m`.`id`\n\t\t\tLEFT JOIN `tallas` AS t ON `m`.`item_talla`=`t`.`id`\n\t\t\tLEFT JOIN `colores` \t AS c ON `m`.`item_color`=`c`.`id`\n\t\t\tWHERE (\n\t\t\t\tLOWER( `item`.`item_nomb` ) LIKE '%" . strtolower($busq) . "%' OR\n\t\t\t\tLOWER( `item`.`item_desc` ) LIKE '%" . strtolower($busq) . "%' OR\n\t\t\t\tLOWER( `item`.`item_precio` ) LIKE '%" . strtolower($busq) . "%' OR\n\t\t\t\tLOWER( `t`.`talla_desc` ) LIKE '%" . strtolower($busq) . "%' OR\n\t\t\t\tLOWER( `t`.`talla_nomb` ) LIKE '%" . strtolower($busq) . "%' OR\n\t\t\t\tLOWER( `c`.`color_nomb` ) LIKE '%" . strtolower($busq) . "%' OR\n\t\t\t\tLOWER( `c`.`color_desc` ) LIKE '%" . strtolower($busq) . "%'\n\t\t\t)\n\t\t\tAND `item`.`deleted` = 0\n\t\t\tGROUP BY item.id\n\t\t\t"); return View::make('indexs.busq')->with('title', $title)->with('art', $art)->with('cat', $cat)->with('subcat', $subcat)->with('busq', $busq); }
<?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();
return View::make('cats/index')->with('cats', $cats); }); Route::get('cats/breeds/{name}', function ($name) { $breed = Breed::whereName($name)->with('cats')->first(); return View::make('cats/index')->with('breed', $breed)->with('cats', $breed->cats); }); Route::get('cats/create', function () { $cat = new Cat(); return View::make('cats.edit')->with('cat', $cat)->with('method', 'post'); }); Route::post('cats', function () { $cat = Cat::create(Input::all()); return Redirect::to('cats/' . $cat->id)->with('message', 'Profil został utworzony!'); }); Route::get('cats/{id}', function ($id) { $cat = Cat::find($id); return View::make('cats.single')->with('cat', $cat); }); Route::get('cats/{cat}/edit', function (Cat $cat) { return View::make('cats.edit')->with('cat', $cat)->with('method', 'put'); }); Route::get('cats/{cat}/delete', function (Cat $cat) { return View::make('cats.edit')->with('cat', $cat)->with('method', 'delete'); }); Route::put('cats/{cat}', function (Cat $cat) { $cat->update(Input::all()); return Redirect::to('cats/' . $cat->id)->with('message', 'Profil został uaktualniony!'); }); Route::delete('cats/{cat}', function (Cat $cat) { $cat->delete(); return Redirect::to('cats')->with('message', 'Profil został usunięty!');
*/ class Dog extends Pet { function play() { // Call the Pet::play() method: parent::play(); echo "<p>{$this->name} is fetching.</p>"; } } // End of Dog class. # ***** END OF CLASSES ***** # // Create a dog: $dog = new Dog('Satchel'); // Create a cat: $cat = new Cat('Bucky'); // Create an unknown type of pet: $pet = new Pet('Rob'); // Feed them: $dog->eat(); $cat->eat(); $pet->eat(); // Nap time: $dog->sleep(); $cat->sleep(); $pet->sleep(); // Have them play: $dog->play(); $cat->play(); $pet->play(); // Delete the objects:
<?php include 'Cat.php'; $cat1 = new Cat(); $cat1->setColor("black"); $cat1->setBreed("Calico"); $cat1->setname("Zoe"); $myCats[] = $cat1; $cat2 = new Cat(); $cat2->setColor("orange"); $cat2->setBreed("Siamese"); $cat2->setname("Garfield"); $myCats[] = $cat2; $cat3 = new Cat(); $cat3->setColor("tabby"); $cat3->setBreed("Lion"); $cat3->setname("Fluffy"); $myCats[] = $cat3; displayCatInfo($cat1); displayCatInfo($cat2); displayCatInfo($cat3); echo "The number of cats of color orange is " . countByColor("orange", $myCats); function displayCatInfo($catExample) { echo "Name: " . $catExample->getName(); echo "<br>"; echo "Color: " . $catExample->getColor(); echo "<br>"; echo "Breed: " . $catExample->getBreed(); echo "<br>"; echo "<br>";
<?php include 'autoload.php'; $cat = new Cat('garfield'); echo $cat->getName() === 'garfield'; echo $cat->meow() === 'Cat garfield is saying meow';
public function testMultipleNamesAndAverageNameLength() { @($cat = new Cat()); $names = ['Chaos', 'Chocolate', 'Felix', 'Garfield', 'Nermal', 'Scratchy']; $totalLength = 0; foreach ($names as $name) { $cat->setName($name); $totalLength += strlen($name); } $allNames = $cat->getNames(); $this->assertEquals(implode(',', $names), $allNames); $this->assertEquals($totalLength / count($names), $cat->getAverageNameLength()); }
<!DOCTYPE html> <html> <head> <title> Hora do Desafio! </title> <link type='text/css' rel='stylesheet' href='style.css'/> </head> <body> <p> <?php // Digite seu código aqui class Cat { public $isAlive = true; public $numLegs = 4; public $name; public function __construct($name) { $this->name = $name; } public function meow() { return 'Meow meow'; } } $siames = new Cat('CodeCat'); echo $siames->meow(); ?> </p> </body> </html>
} public function howOld() { echo $this->name . " is " . $this->age . " years old."; echo "<br>"; echo $this->name . " is " . $this->age . " cat years old!"; echo "<br>"; } public function catWeight() { echo $this->name . " is " . $this->weight . " pound"; } } $cat1 = new Cat("Little Buddy", 2, 8); $cat2 = new Cat("Sneaky Pete", 0, 2); $cat3 = new Cat("Mephisto", 300, 900); $cat1->howOld(); $cat1->feedCat(6); $cat3->howOld(); $cat3->catWeight(); echo "<br>"; echo $cat3->age; echo "<br>"; echo $cat3->weight; ?> </body> </html>
<?php //http://www.php.net/manual/en/language.namespaces.rationale.php namespace my\name; class Cat { static function says() { echo 'meoow\\n'; } } $o = new Cat(); $o->says(); $o = new \my\name\Cat(); $o->says(); echo __NAMESPACE__;
class Cat { public $isAlive = true; public $numLegs = 4; public $name; public function __construct($name) { $this->name = $name; } public function meow() { return "Meow meow"; } } $cat1 = new Cat("CodeCat"); echo $cat1->meow(); die; ?> <!--<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />--> <?php header("Content-type: text/html; charset=utf-8"); ?> <?php // Declarando os valores das variáveis $a = 4; $b = 2; ?> <h2>Adição</h2>
} class Cat implements Animal { protected $name; public function getName() { return $this->name; } public function setName($name) { $this->name = $name; } public function getColour() { } } class Dog { } class Vet { public function treat(Animal $animal) { echo 'The vet has treated ' . $animal->getName(); } } $cat = new Cat(); $cat->setName('Felix'); //echo $cat->getName(); $vet = new Vet(); $vet->treat($cat);
<?php if (isset($_POST["url"])) { $url = $_POST["url"]; $subdomains = array("m.", "www.", "mobile."); $host = str_ireplace($subdomains, "", parse_url($url, PHP_URL_HOST)); } switch ($host) { case "8tracks.com": require "stuff/fetch/EightTracks.php"; $mixId = isset($_POST["mix_id"]) ? $_POST["mix_id"] : false; $trackNumber = isset($_POST["track_number"]) ? $_POST["track_number"] : 0; $please = new EightTracks($output); $please->get($url, $mixId, $trackNumber); break; case "songza.com": require "stuff/fetch/Songza.php"; $stationId = isset($_POST["station_id"]) ? $_POST["station_id"] : false; $sessionId = isset($_POST["session_id"]) ? $_POST["session_id"] : false; $please = new Songza($output); $please->get($url, $stationId, $sessionId); break; default: require "stuff/fetch/Cat.php"; $please = new Cat($output); $please->getCat(); }
class Bird extends Animal { public function __construct($name, $height, $weight, $favFood, $speed, $sound, $canFly) { parent::__construct($name, $height, $weight, $favFood, $speed, $sound, $canFly); } } try { $dog = new Dog('dog', 3, 4, 'cat', 5, 'Bark', false); $playwithanimal = new PlayWithAnimal($dog); echo "<br>"; $dog->tryToFly(); echo "<br>"; $dog->talk(); echo "<br>"; $cat = new Cat('cat', 3, 4, 'mice', 5, 'miow', false); $playwithanimal = new PlayWithAnimal($cat); echo "<br>"; $cat->tryToFly(); echo "<br>"; $cat->talk(); echo "<br>"; $bird = new Bird('Bird', 3, 4, 'insect', 5, 'miow', true); $playwithanimal = new PlayWithAnimal($bird); echo "<br>"; $bird->tryToFly(); echo "<br>"; $bird->talk(); } catch (Exception $e) { echo $e->getMessage(); }
<?php $cat1 = new Cat(); $cat1->setColor("black"); $cat1->setname("Zoe"); $myCats[] = $cat1; $cat2 = new Cat(); $cat2->setColor("orange"); $cat2->setname("Garfield"); $myCats[] = $cat2; $cat3 = new Cat(); $cat3->setColor("tabby"); $cat3->setname("Fluffy"); $myCats[] = $cat3;
<?php /* Кот от кота, а собака от собаки Переопределить метод getChild в классах Cat(кот) и Dog(собака), чтобы кот порождал кота, а собака – собаку. */ class Cat { public static function getChirld() { return new Cat(); } } class Dog { public static function getChirld() { return new Dog(); } } Cat::getChirld(); Dog::getChirld();
<?php include 'Cat.php'; $cat1 = new Cat(); $cat1->setColor("black"); $cat1->setname("Zoe"); $cat1->setBreed("Scottish Fold"); $myCats[] = $cat1; $cat2 = new Cat(); $cat2->setColor("orange"); $cat2->setname("Garfield"); $cat2->setBreed("Persian"); $myCats[] = $cat2; $cat3 = new Cat(); $cat3->setColor("tabby"); $cat3->setname("Fluffy"); $cat3->setBreed("Ragamuffin"); $myCats[] = $cat3; $cont = 0; displayCount($cat1, $cont); // calling the function to count the cats. displayCount($cat2, $cont); displayCount($cat3, $cont); echo "The number of cat that the color is orange is " . $cont; displayCatInfo($cat1); displayCatInfo($cat2); displayCatInfo($cat3); function displayCount($cat, &$cont) { if ($cat->getColor() == 'orange') { //comparison to verify the orange collor
public function getCategoryName() { $category = Cat::findOne($this->cat_id); return $category->title; }
/** * */ public function testBatchWrite_DifferentClasses_WritesObjects() { $dog = new Dog(); $dog->Name = 'Snuffins'; $dog->Color = 'Red'; $cat = new Cat(); $cat->Name = 'Puff daddy'; $cat->HasClaws = true; $batch = new \Batch(); $batch->write(array($dog, $cat)); $this->assertTrue($dog->exists()); $this->assertTrue($cat->exists()); $dog = Dog::get()->first(); $this->assertEquals('Snuffins', $dog->Name); $this->assertEquals('Red', $dog->Color); $cat = Cat::get()->first(); $this->assertEquals('Puff daddy', $cat->Name); $this->assertEquals(1, $cat->HasClaws); }