Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[2.0.4 bug] Cannot use a scalar value as an array #10648

Closed
galki opened this issue Jul 14, 2015 · 3 comments
Closed

[2.0.4 bug] Cannot use a scalar value as an array #10648

galki opened this issue Jul 14, 2015 · 3 comments
Labels
need script to reproduce Script is required to reproduce the issue

Comments

@galki
Copy link

galki commented Jul 14, 2015

I'm using PHP 5.6.8 and getting the below notices when I have error reporting turned on.
It looks like the way an array is written as another array's key is the cause.

// Notice: Cannot use a scalar value as an array in phalcon/mvc/model/resultset/simple.zep on line 209
let renamed[renamedKey[0]] = value;

// Notice: Cannot use a scalar value as an array in phalcon/mvc/model.zep on line 3600
let snapshot[attribute[0]] = value;

@andresgutierrez andresgutierrez added the need script to reproduce Script is required to reproduce the issue label Jul 14, 2015
@olivier-monaco
Copy link
Contributor

@andresgutierrez look here: https://github.com/phalcon/cphalcon/blob/master/phalcon/mvc/model/resultset/simple.zep#L205

                            if !fetch renamedKey, renamedKey[0] {
                                throw new Exception("Column '" . key . "' is not part of the column map");
                            }
                            let renamed[renamedKey[0]] = value;

We replace renamedKey by its first item but them ask for the first item of renamedKey...

It must be

let renamed[renamedKey] = value;

Same for the other notice.

@olivier-monaco
Copy link
Contributor

Usecase:

<?php
$di = new Phalcon\DI();

$di['db'] = new Phalcon\Db\Adapter\Pdo\MySQL([
    "host"     => "localhost",
    "username" => "phalcon_test",
    "password" => "phalcon_test",
    "dbname"   => "phalcon_test",
]);

\Phalcon\Mvc\Model::setup(['castOnHydrate' => true]);

$di['modelsManager'] = new Phalcon\Mvc\Model\Manager();
$di['modelsManager']->setDi($di);
$di['modelsMetadata'] = new Phalcon\Mvc\Model\MetaData\Memory();

class Robot extends Phalcon\Mvc\Model
{
    public $id;
}

$q = new Phalcon\Mvc\Model\Query('select * from Robot limit 1', $di);
$r = $q->execute();
var_dump($r->toArray());

Result:

PHP Notice:  Cannot use a scalar value as an array in phalcon/mvc/model/resultset/simple.zep on line 209 in .../i10673a.php on line 24
PHP Stack trace:
PHP   1. {main}() .../i10673a.php:0
PHP   2. Phalcon\Mvc\Model\Resultset\Simple->toArray() .../i10673a.php:24

Notice: Cannot use a scalar value as an array in phalcon/mvc/model/resultset/simple.zep on line 209 in /volumes/data1/vhosts-dev/libraries/cphalcon-olivier/issues/i10673a.php on line 24

Call Stack:
    0.0001     263952   1. {main}() .../i10673a.php:0
    0.0021     287024   2. Phalcon\Mvc\Model\Resultset\Simple->toArray() .../i10673a.php:24

array(1) {
  [0] =>
  array(1) {
    '' =>
    string(1) "1"
  }
}

@andresgutierrez
Copy link
Sponsor Contributor

Fixed in the 2.0.x branch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
need script to reproduce Script is required to reproduce the issue
Projects
None yet
Development

No branches or pull requests

3 participants