开发者

what does the symbol : mean in php?

I used print_r on some variables of a framework to figure out their contents and what i saw was like this

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

I cant figure out what does the symbol : actually mean? Is it some kind of namespacing?


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.

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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜