PHP 8.0.27 Released!

Voting

: min(five, two)?
(Example: nine)

The Note You're Voting On

someone dot else at elsewhere dot net
9 years ago
@thomas at somewhere dot com

The 'final' keyword is extremely useful.  Inheritance is also useful, but can be abused and becomes problematic in large applications.  If you ever come across a finalized class or method that you wish to extend, write a decorator instead.

<?php
final class Foo
{
    public
method doFoo()
    {
       
// do something useful and return a result
   
}
}

final class
FooDecorator
{
    private
$foo;
   
    public function
__construct(Foo $foo)
    {
       
$this->foo = $foo;
    }
   
    public function
doFoo()
    {
         
$result = $this->foo->doFoo();
         
// ... customize result ...
         
return $result;
    }
}
?>

<< Back to user notes page

To Top