Bug #71673 [NEW]: Cannot access array key with hyphen in it

From: Date: Fri, 26 Feb 2016 19:44:31 +0000
Subject: Bug #71673 [NEW]: Cannot access array key with hyphen in it
Groups: php.bugs php.bugs 
Request: Send a blank email to php-bugs+get-199490@lists.php.net to get a copy of this message
From:             onskulis at yahoo dot de
Operating system: Mac,Linux
PHP version:      5.6.18
Package:          Arrays related
Bug Type:         Bug
Bug description:Cannot access array key with hyphen in it

Description:
------------
Cannot access array key with hyphen in it if passing a variable as key,
but it works with string.

Test script:
---------------
<?php
$test = array('customer-test1' => 1, 'customer-test2' => 2);
function getPost($param) {
	global $test;
    echo $param." = ".$test[$param]."<br/>";
    return isset($test[$param]) ? $test[$param] : NULL;
}
class Customer {
	private $test1;
	private $test2;		
	function __construct() { }
}
$object = new Customer();
$arr = (array)$object;
$newArr = array();
foreach($arr as $key => $val) {
    $newKey = str_replace(get_class($object), "", $key);
    $newArr[$newKey] =
getPost(strtolower(get_class($object))."-".$newKey);
}


-- 
Edit bug report at https://bugs.php.net/bug.php?id=71673&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=71673&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=71673&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=71673&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=71673&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=71673&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=71673&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=71673&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=71673&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=71673&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=71673&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=71673&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=71673&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=71673&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=71673&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=71673&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=71673&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=71673&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=71673&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=71673&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=71673&r=mysqlcfg



Thread (1 message)

  • onskulis at yahoo dot de
« previous php.bugs (#199490) next »