- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
Advertisements