Now you can create objects of this new class with the new statementfor example, you might want to create an object named $lion. Objects such as these are stored in variables in PHP. After you create that object, you can access the get_name and set_name methods using the arrow operator, ->. Here's what that looks like:
<?php
class Animal
{
var $name;
function set_name($text)
{
$this->name = $text;
}
function get_name()
{
return $this->name;
}
}
$lion = new Animal;
$lion->set_name("Leo");
echo "The name of your new lion is ", $lion->get_name(), ".";
?>
No hay comentarios:
Publicar un comentario