Monday 13 October 2014

Re: [dcphp-dev] Digest for washington-dcphp-group@googlegroups.com - 1 update in 1 topic

Hello Ray,

In this context it's practically the same thing, the behavior changes when used in an inheritance context with static calls
expl : 

Class Thing 

    const PRIMARY_KEY = 'key'; 
    public static function keys() 
    { 
        $x = self::PRIMARY_KEY; 
        $y = static::PRIMARY_KEY; 
        return $x . $y; 
    } 

Class Otherthing extends Thing
{
    const PRIMARY_KEY = 'Another key'; 
}
echo Thing::keys(); 
echo Otherthing::keys();


will output
keykey
keyAnother key


This is called late static binding, which was introduced in PHP 5.3



On 13 October 2014 13:34, <washington-dcphp-group@googlegroups.com> wrote:
Ray <ray.paseur@gmail.com>: Oct 12 04:32PM -0400

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 digest because you're subscribed to updates for this group. You can change your settings on the group membership page.
To unsubscribe from this group and stop receiving emails from it send an email to washington-dcphp-group+unsubscribe@googlegroups.com.

--
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