New Object

Discussion in 'PHP' started by Shaimaa, May 26, 2010.

  1. #1
    I have an error on this line:
    class matchController extends baseController {
    private $match = new Match();
    ....
    }

    the Class Match is located in another folder different from matchController

    The error is:
    Parse error: syntax error, unexpected T_NEW in /var/www/kora/trunk/controller/matchController.php on line 5
     
    Shaimaa, May 26, 2010 IP
  2. lukeg32

    lukeg32 Peon

    Messages:
    645
    Likes Received:
    19
    Best Answers:
    1
    Trophy Points:
    0
    #2
    This is invalid.

    You can define the property as string, numeric, array (etc) but not a return value of a function or object.

    You should initialise it in the constructor instead.

    class matchController extends baseController
    	{
    	private $match;
    
    	function __construct()
    		{
    		$this->match = new Match();
    		}
    	}
    PHP:
     
    lukeg32, May 26, 2010 IP
  3. Shaimaa

    Shaimaa Peon

    Messages:
    28
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Now I am doing the following
    the error is:

    Fatal error: Class 'Match' not found in /var/www/kora/trunk/controller/matchController.php on line 10
     
    Shaimaa, May 26, 2010 IP
  4. gapz101

    gapz101 Well-Known Member

    Messages:
    524
    Likes Received:
    8
    Best Answers:
    2
    Trophy Points:
    150
    #4
    I think Match is a model, so you need to load or autoload it
     
    gapz101, May 26, 2010 IP
  5. kidatum

    kidatum Peon

    Messages:
    61
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    1. You have to declare a variable and then initialize it with $this-> keyword.
    2. You have to include your Match class in this script using include() function, or require() function. Else, your Match class can be below or above your current class.

    Where is your Match class located?
     
    kidatum, May 26, 2010 IP