On class properties

<?php
class foo  {
  static public
$bar = 2;
}

print
foo::$bar;
$n = new foo;
print
$n->bar;
print
$n->$bar;
?>

Results?
2
PHP Notice:  Undefined property: foo::$bar
PHP Notice:  Undefined variable: bar
PHP Fatal error:  Cannot access empty property

Moral of the story: making a property static means that it's mandatory to reach it via the :: operator. It's not accessible as a normal property any more.

Comments

Of course

It's not the same variable. It's bound to a totally different scope. statics are just globals with restricted access and a funny hat.

This isn't a WTF, this is the way any reasonable language should work. (This was not the case in PHP 4, which was not a reasonable language where anything involving objects is concerned.)

Some languages (Java) allow

Some languages (Java) allow you to access static members though an instance, but it's the exception rather than the rule. PHP is more correct (and more explicit) here.

Python also allows accessing

Python also allows accessing static members through instances. Why wouldn't you?

Nice code. Seems a little

Nice code. Seems a little short but, PHP is very interesting if we get a hold on it.
GE CSCP5UGXSS

PHP is very very flexible in

PHP is very very flexible in accessing member variables and member functions. These access methods maybe look unusual and unnecessary at first glance; but they are very useful sometimes
Motorcycle lawyer

That was a really good

That was a really good article, thanks for taking the time to put it together! You have managed to point out some very good points. I can't say that I completely agree about some points, but you certainly have a unique perspective. Anyway, I like your post.hypnosis to stop smoking

I really loved this kind of

I really loved this kind of post, if I have your permission may i duplicate this post to my blog and share it with other people as well. Naturally I'm going to give the original credits to you only.
mole remover

I Really enjoyed your blog. I

I Really enjoyed your blog. I just bookmarked it. I am a regular visitor of your website I will share It with my friends

You had some nice points

You had some nice points here. I done a research on the topic and got most peoples will agree with you

A query cannot compare two

A query cannot compare two list values. There is no way to test two lists for equality without testing each element for membership separately.
free reverse cell phone lookup

"Jogging Tips" Thanks for

"Jogging Tips"

Thanks for sharing this information. I really like your way of expressing the opinions and sharing the information. It is good to move as chance bring new things in life, paves the way for advancement,

A query cannot compare two

A query cannot compare two list values. There is no way to test two lists for equality without testing each element for membership separately

Casio Uhrenarmband

It is great to have the

It is great to have the opportunity to read a good quality article with useful information on topics that plenty are interested on
70-667 exam
642-617 exam
642-661 exam
310-202 exam
642-637 exam
1z0-043 exam
ITIL exam
646-204 exam

It is so lucky to read your

It is so lucky to read your blog,it is full of useful message.I wish we both can do better in the future.It great honor if you can visit our website,and give us some suggestion.
1z0-051 dumps
E20-001 dumps
70-630 dumps
N10-003 dumps
83-640 dumps
70-536 dumps
1z0-052 dumps
352-001 dumps

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <blockquote>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

More information about formatting options