Skip to content

Instantly share code, notes, and snippets.

@barkerja
Created December 6, 2011 07:22
Show Gist options
  • Save barkerja/1437182 to your computer and use it in GitHub Desktop.
Save barkerja/1437182 to your computer and use it in GitHub Desktop.
PHP Late Static Binding
<?php
class Foo {
public static function name() {
echo __CLASS__;
}
}
class Bar extends Foo {
}
Foo::name();
Bar::name();
@barkerja
Copy link
Author

barkerja commented Dec 6, 2011

Expected Results:
FooBar

Actual Results:
FooFoo

@barkerja
Copy link
Author

barkerja commented Dec 6, 2011

Instead of CLASS, you must call get_called_class() which supports late static binding thus providing the expected results
of “FooBar”

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment