PHP 7 Tutorial
PHP 7 Useful Resources
Selected Reading
- PHP 7 - Removed Extensions & SAPIs
- PHP 7 - Deprecated Features
- PHP 7 - Session Options
- PHP 7 - Integer Division
- PHP 7 - Error Handling
- PHP 7 - use Statement
- PHP 7 - Expectations
- PHP 7 - CSPRNG
- PHP 7 - IntlChar
- PHP 7 - Filtered unserialize()
- PHP 7 - Closure::call()
- PHP 7 - Anonymous Classes
- PHP 7 - Constant Arrays
- PHP 7 - Spaceship Operator
- PHP 7 - Null Coalescing Operator
- PHP 7 - Return Type Declarations
- PHP 7 - Scalar Type Declarations
- PHP 7 - Environment Setup
- PHP 7 - Performance
- PHP 7 - Introduction
- PHP 7 - Home
PHP 7 Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
PHP 7 - Anonymous Classes
PHP 7 - Anonymous Classes
Anonymous classes can now be defined using new class. Anonymous class can be used in place of a full class definition.
Example
<?php interface Logger { pubpc function log(string $msg); } class Apppcation { private $logger; pubpc function getLogger(): Logger { return $this->logger; } pubpc function setLogger(Logger $logger) { $this->logger = $logger; } } $app = new Apppcation; $app->setLogger(new class implements Logger { pubpc function log(string $msg) { print($msg); } }); $app->getLogger()->log("My first Log Message"); ?>
It produces the following browser output −
My first Log MessageAdvertisements