- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Instance child class in abstract static method PHP?
For this, use $anyObjectName=new static() along with self.
Example
The PHP code is as follows
<!DOCTYPE html> <html> <body> <?php abstract class Base{ protected static $fullName = ''; abstract protected function customFunction(); public static function get_obj($param1 = null, $param2 = null){ $obj = new static(); $obj->customFunction(); } public static function getFullName(){ return static::$fullName; } } class Child extends Base { protected static $fullName = 'John Doe'; protected function customFunction(){ echo self::getFullName() . "<br>"; echo $this; } } Child::get_obj(); ?> </body> </html>
Output
This will produce the following output
John Doe
- Related Articles
- Explain STATIC AND INSTANCE method in PHP.
- How to call a non-static method of an abstract class from a static method in java?
- Explain abstract class in PHP.
- How to create an instance of an abstract class in Kotlin?
- Declare static variables and methods in an abstract class in Java
- Can we define an abstract class without abstract method in java?
- Why can't static method be abstract in Java?
- Why static methods of parent class gets hidden in child class in java?
- Class method vs static method in Python
- Can we declare an abstract method final or static in java?
- What is the difference between Static class and Singleton instance in C#?
- Can we access the instance variables from a static method in Java?
- Sequence of execution of, instance method, static block and constructor in java?
- How to call parent constructor in child class in PHP?
- Abstract class in Java

Advertisements