|
|
|
| Ребят, имеется вот такой вот код.
index.php
include "Game.php";
include "Player.php";
$game = new Game();
$game->createPlayer('ted');
$game->showPlayer();
|
player.php
class Player
{
public $name;
public $hp;
public $dmg;
function __construct(Game $g, $name)
{
$this->name = $name;
echo "Player {$this->name} was created<br>";
}
function __toString()
{
echo "Name: {$this->name} | HP: {$this->hp} | DMG: {$this->dmg}";
}
}
|
Game.php
class Game
{
function __construct()
{
echo "Game Started<br>";
}
function createPlayer($name)
{
$this->player = new Player($this, $name);
}
function showPlayer()
{
echo $this->player;
}
}
|
Теперь проясните мне пожалуйста вот эти строки, конкретно, что выделено жирным.
function __construct(Game $g, $name)
$this->player = new Player($this, $name)
и почему когда я убираю конструкцию __toString вылезает ошибка.
Буду очень благодарен. | |
|
|