static:: uses late static binding whereas self does not. If you were to extend Thing and redefine PRIMARY_KEY (say, to 'foobar'), running keys() on an instance of that subclass would return 'keyfoobar'.
Put another way, self:: always refers only to the class it is written in, while static:: refers to the class context in which it is run.
In this code snippet, I get output that says "keykey"
What is the difference between the meanings of static:: and self:: in
this or any other context. Any man page reference would be gratefully
received!
<?php
error_reporting(E_ALL);
Class Thing
{
const PRIMARY_KEY = 'key';
public function keys()
{
$x = self::PRIMARY_KEY;
$y = static::PRIMARY_KEY;
return $x . $y;
}
}
$thing = new Thing;
var_dump($thing->keys());
Thanks and regards, Ray
--
You received this message because you are subscribed to the Google
Group: "Washington, DC PHP Developers Group" - http://www.dcphp.net
To post, send email to washington-dcphp-group@googlegroups.com
To unsubscribe, send email to washington-dcphp-group+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/washington-dcphp-group?hl=en
---
You received this message because you are subscribed to the Google Groups "Washington, DC PHP Developers Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to washington-dcphp-group+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to the Google
Group: "Washington, DC PHP Developers Group" - http://www.dcphp.net
To post, send email to washington-dcphp-group@googlegroups.com
To unsubscribe, send email to washington-dcphp-group+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/washington-dcphp-group?hl=en
---
You received this message because you are subscribed to the Google Groups "Washington, DC PHP Developers Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to washington-dcphp-group+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
0 comments:
Post a Comment