0

I am trying to declare an object of type Spell in my class Game like this:

<?php
require 'Spell.php';

class Game
{

    public $Name;
    public $Spell;

    function Game()
    {
        $Name[0] = 0;
        $Spell = new Spell;

    }

This is returning this warning:

"Warning: Creating default object from empty value in"

and I'm not sure why.

Jonathon Reinhart
  • 132,704
  • 33
  • 254
  • 328

2 Answers2

0

You should use

function Game()
{
    $this->Name = [ 0 ];
    $this->Spell = new Spell();
}

Check this question for more details on the error.

Community
  • 1
  • 1
Nikolai Samteladze
  • 7,699
  • 6
  • 44
  • 70
0

Try the following:

class Game
{

    public $Name = array();
    public $Spell;

    function Game()
    {
        $this->Name[0] = 0;
        $this->Spell = new Spell();

    }
}
Barmar
  • 741,623
  • 53
  • 500
  • 612
Jensman
  • 60
  • 6