We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Config can't load from CLI

Hi all,

My config file, which gets parsed and loads just fine when loading from web-oriented code, generates a number of errors when I try to load it from the CLI. The code in my config.php file looks like this

$Config = new Phalcon\Config([ 
    /* array of configuration data */ 
]); // <-- This is line 115

return $Config

The error is:

 PHP Warning:  Phalcon\Config::__construct(): Property should be string in /path/to/app/config/config.php on line 115

repeated 3 times

Pulling stuff out of my config array until the problem went away, I see the error is caused by this property:

,'roles' =>  [
         1  =>  'Admin'
        ,2  =>  'Employee'
        ,3  =>  'Student'   
]

Ok, the error makes sense now, but why it's happening is still a mystery. I'm using the exact same file for my web-based code and it's not causing a problem. Plus, when I wrap the 1, 2 & 3 in quotes, I still get the error.

Update: Forgot to mention I'm running 1.3.0

You appear to be running pre-1.2.1 version of Phalcon

$ cat cfg.php 
<?php
$config = array(
        'roles' => array(
                1  =>  'Admin'
                ,2  =>  'Employee'
                ,3  =>  'Student'
        )
);

$c = new Phalcon\Config($config);
print_r($c);

$ php cfg.php 
Phalcon\Config Object
(
    [roles] => Phalcon\Config Object
        (
            [1] => Admin
            [2] => Employee
            [3] => Student
        )

)

Crap, I forgot to mention I'm actually running 1.3.0

OK, does my example above work for you?

No it does not. I get 3 errors, all apparently thrown from line 11:

$c = new Phalcon\Config($config); // line 11

$c->roles is a Phalcon\Config object, but it has no properties. I wonder if this is something better mentioned on Github as a possible bug?

OK, are you running Windows version of Phalcon?

Nope, running on Debian, compiled source pulled from Github a few days ago.