Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

adense's avatar

Syntax error in PHP class used from Blade View file

I've created a PHP file which holds a class. I access this by using "use App\Classes\ConfigurationClass;" from my blade view file, and it works fine. However, it complains about the following:

Parse error: syntax error, unexpected '$config_id' (T_VARIABLE), expecting function (T_FUNCTION) (View: /var/www/html/minasidor/resources/views/konfig.blade.php)

..which refers to the line $config_id seen below in the code here:

class ConfigurationClass{
        //"unique" id for database insertion
        $config_id;
        //array to hold all TYPES of products
    $productTypes;

       //holds ALL products
       $products;
       //holds ALL programming
       $programming;

        function __construct($config_id) {
            $this->config_id = $config_id;
            $this->products = array();
            $this->programming = array();
        }
...and so on...

This is how I use the class from my blades view:

Session::set('configuration', (new ConfigurationClass(0)));

If I remove all variables and remove all references to them from the constructor, it works. What is causing this?

0 likes
6 replies
tomopongrac's avatar
Level 51

Try this

class ConfigurationClass {

    //"unique" id for database insertion
    protected $config_id; // or put public
    
    //array to hold all TYPES of products
    protected $productTypes; // or put public

    //holds ALL products
    protected $products; // or put public
    //holds ALL programming
    protected $programming; // or put public

    public function __construct($config_id)
    {
        $this->config_id = $config_id;
        $this->products = array();
        $this->programming = array();
    }
adense's avatar

@tomo_pongrac Thanks that solved the issue with that line. Now, however, I get this: Fatal error: Call to undefined function App\Classes\initInfo()

I even tried to put public in front of the function as well, but to no avail!

EDIT: initInfo() is a function I call from within the constructor. (I added that line)

tomopongrac's avatar

Can you paste code with that and where is located file with that function...

adense's avatar

@tomo_pongrac Here is the code that causes the error:

class ConfigurationClass{
        //"unique" id for database insertion
        public $config_id;
        //array to hold all TYPES of products
        public $productTypes;

        //holds ALL products
        public $products;
        //holds ALL programming
        public $programming;

        public function __construct($config_id) {
            $this->config_id = $config_id;
            $this->products = array();
            $this->programming = array();
            initInfo();
        }

        public function initInfo(){
        //Actually empty in here!!
        }

I get this error:

ErrorException in ConfigurationClass.php line 26:
Fatal error: Call to undefined function App\Classes\initInfo() (View: /var/www/html/minasidor/resources/views/konfig.blade.php)
tomopongrac's avatar

@adense

You need this in contructor

public function __construct($config_id) {
            $this->config_id = $config_id;
            $this->products = array();
            $this->programming = array();
            $this->initInfo();
        }

Please or to participate in this conversation.