开发者

PHP Array Object show unexpected T_DOUBLE_ARROW error

开发者 https://www.devze.com 2023-04-11 09:34 出处:网络
I have a problem, which seems to be in line $this->pd_db = object( The shown error is Parse e开发者_如何学Pythonrror: syntax error, unexpected T_DOUBLE_ARROW in /var/www/website/includes/PD.php on

I have a problem, which seems to be in line $this->pd_db = object(

The shown error is

Parse e开发者_如何学Pythonrror: syntax error, unexpected T_DOUBLE_ARROW in /var/www/website/includes/PD.php on line 10 `

Here is my code

$this->pd_db = object(
  'cstm'  => object(
    'table_name'      => "customdata",
    'table_version'   => '1.0'
  )
);

Please solve this.


I suspect that it should look like :

$this->pd_db = (object)array(
  'cstm'  => (object)array(
    'table_name'      => "customdata",
    'table_version'   => '1.0'
  )
);

Though this seems like a pretty horrible idea...


It looks like you're trying to create an associative array, in which case you want:

$arr = array(
    'key1' => 'val1',
    'key2' => 'val2',
);

If you are actually wanting to use an object, object instantiation cannot be done with that syntax. You would have to create an object and assigned properties:

$obj = new stdObject;
$obj->key1 = 'val1';

Edit: Did not know that you can cast an array to an object. If that is your goal, tereško's way is better.

0

精彩评论

暂无评论...
验证码 换一张
取 消