Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling a super method in PHP

Tags:

oop

php

Can you do something like this in PHP:

function foo() {     super->foo();      // do something } 
like image 819
Emanuil Rusev Avatar asked Sep 20 '10 19:09

Emanuil Rusev


People also ask

What is PHP super?

Several predefined variables in PHP are "superglobals", which means they are available in all scopes throughout a script. There is no need to do global $variable; to access them within functions or methods. These superglobal variables are: $GLOBALS. $_SERVER.

How do you call a parent class in PHP?

To call the constructor of the parent class from the constructor of the child class, you use the parent::__construct(arguments) syntax. The syntax for calling the parent constructor is the same as a regular method.

Does PHP have inheritance?

Inheritance is a well-established programming principle, and PHP makes use of this principle in its object model.


1 Answers

Yes, it's called parent:: though.

public function foo() {     parent::foo(); // this is not a static method call, even though it looks like one      //do something } 
like image 125
davidtbernal Avatar answered Sep 28 '22 01:09

davidtbernal