Skip to content

Instantly share code, notes, and snippets.

@wizardishungry
Created July 24, 2012 16:01
Show Gist options
  • Save wizardishungry/3170861 to your computer and use it in GitHub Desktop.
Save wizardishungry/3170861 to your computer and use it in GitHub Desktop.
Test my assumptions about how self:: works / late static binding
<?php
/*
http://php.net/manual/en/language.oop5.late-static-bindings.php
*/
class Adam {
const LORD='Adonai';
public $knowledge = self::LORD;
public function getLord() { return self::LORD; }
public function getTrueLord() { return static::LORD; }
}
class Abel extends Adam {
const LORD='Yhwh';
}
$a = new Abel();
echo $a->knowledge, "\n";
echo $a->getLord(), "\n";
echo $a->getTrueLord(), "\n";
Yhwh
Adonai
Yhwh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment