【发布时间】:2010-12-04 01:21:58
【问题描述】:
将命名空间对象转换为数组时出现意外结果。
<?php
namespace package\test;
class Test {
private $foo;
private $bar;
}
$test = new Test();
$testArray = (array) $test;
var_dump($testArray);
输出是
array
'�package\test\Test�foo' => null
'�package\test\Test�bar' => null
不确定� 中的那些var_dump 字符是什么?我查看了源代码,它似乎是&#0;。基本上我需要做的是修剪键,所以它最终是
array
'foo' => null
'bar' => null
但我不确定如何使用正则表达式来定位那些� 字符以摆脱我不想要的部分?这适用于 PHP 5.3.3。谢谢。
【问题讨论】:
标签: php oop namespaces