示例#1
0
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>
<p>
示例#2
0
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();
<!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>
示例#4
0
<?php

include 'autoload.php';
$cat = new Cat('garfield');
echo $cat->getName() === 'garfield';
echo $cat->meow() === 'Cat garfield is saying meow';
示例#5
0
 * 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();
<?php

class Cat
{
    public $isAlive = true;
    public $numLegs = 4;
    public $name;
    public function __construct($name)
    {
        $this->name = $name;
    }
    public function meow()
    {
        return "Meow meow";
    }
}
$cat = new Cat("CodeCat");
echo $cat->meow();