Skip to content

Instantly share code, notes, and snippets.

@vbarbarosh
Last active May 21, 2019 18:32
Show Gist options
  • Save vbarbarosh/4e5ee3139d58b901395ce1796d0e2de5 to your computer and use it in GitHub Desktop.
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
<?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