reference - PHP: variable value mysteriously set to 0 -
thanks in advance help! have situation i'm trying debug variable mysteriously set 0.
i know xdebug (using phpstorm) happens @ specific line:
// breakpoint here: $id_key 'my_entity_id_key' $e_entity_ids = my_module_fetch_col_keyed($query, $id_key, $created_column); // breakpoint here: $id_key 0
it's weird, because $id_key
not reference, nor function take reference parameter. also, after value has changed 0
, $id_key
blue in variables pane of debugger.
i've tried making copy of variable , using pass function instead:
$id_key2 = $id_key; $e_entity_ids = my_module_fetch_col_keyed($query, $id_key2, $created_column); // breakpoint here: $id_key 0, , $id_key2
i'm wondering:
- how value of
$id_key
mysteriously changing 0? - how can create copy of
$id_key
it's not changed when pass copymy_module_fetch_col_keyed()
? - what mean when variable name blue in variables pane in phpstorm?
when step my_module_fetch_col_keyed()
, there's line after $column mysteriously 0
, shown:
function my_module_fetch_col_keyed($query, $column, $key_column = null) { try { $result = $query->execute(); } catch (exception $e) { return false; } if (!isset($key_column)) { try { // breakpoint here: $column 'my_entity_id_key' $column_results = $result->fetchcol($column); // breakpoint here: $column mysteriously 0 } catch (exception $e) { return false; } return $column_results; } try { $assoc = $result->fetchallassoc($key_column); } catch (exception $e) { return false; } $keyed = array(); foreach ($assoc $key => $result) { $keyed[$key] = $result->{$column}; } return $keyed; }
and $result->fetchcol()
function 1 liner calls pdostatement::fetchall()
:
class databasestatementbase extends pdostatement implements databasestatementinterface { [...] public function fetchcol($index = 0) { return $this->fetchall(pdo::fetch_column, $index); } // function fetchall() not overridden parent pdostatement [...] }
edit: tried putting
$id_key
object property , using magic __set()
method backtrace , find out when variable changed: class test { private $id_key; protected $values = array(); public function __set($key, $value) { if ($key == 'id_key') { $b = debug_backtrace(); "hello world!"; } if (method_exists(get_parent_class($this), '__set')) { return parent::__set($key, $value); } return $this->values[$key] = $value; } public function __get($key) { return isset($this->values[$key]) ? $this->values[$key] : 1; } }
and updated code so:
$e_entity_ids = basic_functions_fetch_col_keyed($query, $test->id_key, $created_column);
everything keeps working same way was, , $test->id_key
evaluates my_entity_id_key
before , 0
after. set breakpoints in __set()
, __get()
methods, , examined values when called (for example, in above line called in basic_functions_fetch_col_keyed($query, $test->id_key, $created_column)
). but, weirdly, __set()
magic function not called when value set 0
. i'm lost! appreciated!!
it sure me id_key being passed reference.
some of pdo libraries coded in c. it's quite possible in innards variables corrupted there.
tbf you're passing string argument expects numeric value, standpoint of functions you're using, new value same old value (most text strings not containing digits = 0).
Comments
Post a Comment