View Issue Details

IDProjectCategoryView StatusLast Update
0000925Xdebugpublic2013-06-22 13:39
Reporterbobl Assigned Toderick  
PrioritynormalSeveritycrashReproducibilityalways
Status resolvedResolutionunable to reproduce 
Platformeclipse-pdt OSwindows7OS Versionsp1
Product Version2.2.1 
Summary0000925: crash accessing php object properties
Description

Something funny happens with object property access described below. Note I encountered this inspecting various objects generated using json_decode() output.

<?php
error_reporting(-1);
$obj = new stdClass;
$prop = "crash-me";
$arr = array();
$obj->$prop = "no crash";
$obj->$prop = $arr; // bp here and $obj->$prop is correct
print_r($obj); // bp here, inspect $obj->$prop and... xdebug/php will crash.
exit;

More details are below in steps to reproduce.

Thank you!

Steps To Reproduce

http://stackoverflow.com/questions/14902335/need-help-understanding-php-object-property-names-versus-array-keys (see steps to reproduce)

I'm having some trouble using PHP object property names in a flexible way, similar to array keys.

My understanding is that an array key can be any string or integer, e.g

$arr = array("crash-me" => "value");

is a valid key/value pair.

Now if I "cast" that to an object:

$obj = (object) $arr;

have I done something illegal, because of the dash in the key string?

A simple example shows my dilema:

<?php
error_reporting(-1);
$obj = new stdClass;
$prop = "crash-me";
$arr = array();
$obj->$prop = "no crash";
$obj->$prop = $arr; // bp here and $obj->$prop is correct
print_r($obj); // bp here, inspect $obj->$prop and... xdebug/php will crash.
exit;

This will crash eclipse-pdt using xdebug when you inspect the value of the $obj before the print_r().

However, without bp, contents are printed correctly from print_r() at exit.

stdClass Object ( [crash-me] => Array ( ) )

Note that if I stuff something into the array when assigning it to the property, things are OK:

$obj = new stdClass;
$prop = "crash-me";
$arr = array("works_ok");
$obj->$prop = "no crash";
$obj->$prop = $arr;
print_r($obj);
exit;

Bottom-line, I'd like to use property names with dashes and possibly other punctuation similar to array key. Is it possible? Or am I doing something illegal by assigning an empty array, in which case wouldn't an error be caught?

Thanks ahead for your kind consideration!

on edit, I forgot another part of puzzle - the code below does not crash. In this case, the property name does not have a dash, however, the array key is empty!

$obj = new stdClass;
$prop = "crash_me"; // note underscore
$arr = array();
$obj->$prop = "no crash";
$obj->$prop = $arr; // bp here and $obj->$prop is correct
print_r($obj); // bp here, inspect $obj->$prop and... no crash!
exit;

Sorry for the confusion! It's probably something obvious I am missing.

On second edit-

To clarify, I was hoping to read property names from json_decode() and simply use the objects without having to convert to arrays. It was an experiment with dynamic code generation using keys from json data files. Per discussion below, looks like if I want to continue with PHP for this, I'll need the $arr['key1']['key2']... syntax and have the decoder use the "array" flag.

Thanks for the great replies!

TagsNo tags attached.
Operating Systemwind7 sp1
PHP Version5.3.15-5.3.19

Activities

derick

2013-05-22 05:48

administrator   ~0002479

Could you please try Xdebug 2.2.3 which has just been released? I am suspecting that release might fix this issue.

derick

2013-06-09 10:21

administrator   ~0002499

Hello - can you please try 2.2.3?

derick

2013-06-22 13:39

administrator   ~0002514

Unable to reproduce, and no feedback provided. Please reopen if this is still an issue for you.

Issue History

Date Modified Username Field Change
2013-02-15 21:56 bobl New Issue
2013-05-22 05:48 derick Note Added: 0002479
2013-05-22 05:48 derick Assigned To => derick
2013-05-22 05:48 derick Status new => feedback
2013-06-09 10:21 derick Note Added: 0002499
2013-06-22 13:39 derick Note Added: 0002514
2013-06-22 13:39 derick Status feedback => resolved
2013-06-22 13:39 derick Resolution open => unable to reproduce
2016-07-31 12:35 derick Category Debug client (console) => debugclient (debugging tool)
2016-07-31 12:35 derick Category debugclient (debugging tool) => (No Category)