Skip to content

Instantly share code, notes, and snippets.

@adrienbrault
Created May 25, 2012 20:31
Show Gist options
  • Save adrienbrault/2790409 to your computer and use it in GitHub Desktop.
Save adrienbrault/2790409 to your computer and use it in GitHub Desktop.
PHP static keyword example
<?php
class A
{
public static function create()
{
return new static();
}
}
class B extends A {}
$object1 = A::create();
$object2 = B::create();
echo get_class($object1) . PHP_EOL;
echo get_class($object2) . PHP_EOL;
@adrienbrault
Copy link
Author

Output:

A
B

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