Schrodinger's cat
Schrodinger's cat

Reputation: 1102

Object not an instance of desired class

The following is what I have in index.php

<?php
require_once __DIR__.'/controllers/trackercontroller.php';

$oTracker = new trackerController();
var_dump($oTracker);
?>

and the output for oTracker is

object(trackerController)#1 (0) { }

And my trackerController in controllers/trackercontroller.php is

class trackerController{
    public $test = "hi";
    function __construct($oReader){

}

Why am I unable to view the class property test when I var_dump() the object?

Upvotes: 1

Views: 42

Answers (1)

Sanjay Chaudhari
Sanjay Chaudhari

Reputation: 420

You should have to follow object oriented concept for PHP like

use \controller\TrackerController;

$oTracker = new TrackerController();
var_dump($oTracker->test);

Here TrackerController is the class name.

Hope this will help you.

Upvotes: 1

Related Questions