Last active
May 21, 2019 18:32
-
-
Save vbarbarosh/4e5ee3139d58b901395ce1796d0e2de5 to your computer and use it in GitHub Desktop.
php_class_ctor_parent – Generic way to call base class constructor https://codescreens.com
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
# Generic way to call base class constructor | |
class Foo | |
{ | |
public function __construct() | |
{ | |
echo "FOO\n"; | |
} | |
} | |
class Bar extends Foo | |
{ | |
public function __construct() | |
{ | |
call_user_func_array([$this, 'parent::__construct'], func_get_args()); | |
echo "BAR\n"; | |
} | |
} | |
new Foo(); | |
# FOO | |
new Bar(); | |
# FOO | |
# BAR |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment