I used print_r
on some variables of a framework to figure out their contents and what i saw was like this
我在框架的一些变量上使用print_r来弄清楚它们的内容,我看到的是这样的
Array (
[pages:navigation] => Navigation
[pages:via] => via pages
[item:object:page_top] => Top-level pages
)
I thought this was ok because i can create arrays like
我认为这很好,因为我可以创建像这样的数组
$ar=array('pages:navigation' => 'Navigation',
'pages:via' => 'via pages');
and it would be no problem but when i create this
这将是没有问题,但当我创建这个
class student {
public $name;
public function get_name() {
return $name;
}
private $id;
public function get_id() {
return $id;
}
protected $email;
}
$s = new student();
$s->name="hi";
print_r($s);
I get this:
我明白了:
student Object ( [name] => hi [id:student:private] => [email:protected] => )
here the symbol :
is automatically inserted for id
indicating that it is a member of student
and is private
but it is not inserted for public
member name
这里符号:自动插入id表示它是学生的成员并且是私有的,但是没有插入公共成员名称
I cant figure out what does the symbol :
actually mean? Is it some kind of namespacing?
我无法弄清楚这个符号是什么意思?它是某种命名空间吗?
2 个解决方案
#1
3
In the array, it has no special meaning. It's just part of the string key; an array key can be any string or integer.
在数组中,它没有特殊含义。它只是字符串键的一部分;数组键可以是任何字符串或整数。
In the object, it's just how print_r
displays property names for private properties.
在对象中,print_r显示私有属性的属性名称。
In id:student:private
, id
is the property name, student
the class in which the property is declared, and private
is the visibility of the property.
在id:student:private中,id是属性名称,student是声明属性的类,private是属性的可见性。
#2
1
Chances are it's what the script/page is using to separate values in the key
of the array. They may use spaces in key names so using a space wasn't acceptable and needed a character that wouldn't normally be found in the value itself.
有可能是脚本/页面用于分隔数组键中的值。它们可能在键名中使用空格,因此使用空格是不可接受的,并且需要通常在值本身中找不到的字符。
Much like namespaces in many other languages use the .
as a delimiter, that script decided to use :
(which is then parsed at a later date most likely and used as its originally intended).
很像许多其他语言中的命名空间使用。作为分隔符,该脚本决定使用:(然后在最近的日期对其进行解析,并将其用作最初的预期)。
Without seeing the script in it's entirety, this would only be a guess as to implementation.
如果没有完整地看到脚本,这只是对实现的猜测。
#1
3
In the array, it has no special meaning. It's just part of the string key; an array key can be any string or integer.
在数组中,它没有特殊含义。它只是字符串键的一部分;数组键可以是任何字符串或整数。
In the object, it's just how print_r
displays property names for private properties.
在对象中,print_r显示私有属性的属性名称。
In id:student:private
, id
is the property name, student
the class in which the property is declared, and private
is the visibility of the property.
在id:student:private中,id是属性名称,student是声明属性的类,private是属性的可见性。
#2
1
Chances are it's what the script/page is using to separate values in the key
of the array. They may use spaces in key names so using a space wasn't acceptable and needed a character that wouldn't normally be found in the value itself.
有可能是脚本/页面用于分隔数组键中的值。它们可能在键名中使用空格,因此使用空格是不可接受的,并且需要通常在值本身中找不到的字符。
Much like namespaces in many other languages use the .
as a delimiter, that script decided to use :
(which is then parsed at a later date most likely and used as its originally intended).
很像许多其他语言中的命名空间使用。作为分隔符,该脚本决定使用:(然后在最近的日期对其进行解析,并将其用作最初的预期)。
Without seeing the script in it's entirety, this would only be a guess as to implementation.
如果没有完整地看到脚本,这只是对实现的猜测。