ArtisanTinkerer.github.io

Blog

View on GitHub

Modern PHP

Namespaces

Autoloading

Interfaces

Traits

Generators

Generators are simple iterators.

Closures

Chapter 3 Standards

Sanitize

$input = '<p><script>alert("You won the Nigerian lottery!");</script></p>';
echo htmlentities($input, ENT_QUOTES, 'UTF-8');

use filter_var for email address etc.

PHP Objects, Patterns, and Practice

##Part 3 - Object Basics

Invoking an Overridden Method

Extending the parent method:

// ShopProduct class...
function getSummaryLine() 
{
    $base = "{$this->title} ( {$this->producerMainName}, ";
    $base .= "{$this->producerFirstName} )";
    return $base;
}
// BookProduct class...
function getSummaryLine() 
{
    $base = parent::getSummaryLine();
    $base .= ": page count - {$this->numPages}";
    return $base;
}

Chapter 4 Advanced Features

Late Static Binding

This means that you can do this in the base class:

abstract class DomainObject  
{
    public static function create() {
        return new static();
    }

and you will actually get a child class (assuming that Document extends DomainObject):

Document::create();
final class Checkout

Working with Interceptors (overloading)

__get() and __set() are using for getting and setting properties which don’t exist

class Person {
    function __get( $property ) {
        $method = "get{$property}";
        if ( method_exists( $this, $method ) ) {
            return $this->$method();
        }
}

Clone

Callbacks, Anonymous Functions and Closures

Class and Object Functions;

The Reflection API

Part 3 Patterns

Composition and Inheritance

Using Composition - The Strategy Pattern

missing

Singleton Pattern

Factory

function getApptEncoder() {
    switch ( $this->mode ) {
        case ( self::MEGA ):
      return new MegaApptEncoder();
   default:
     return new BloggsApptEncoder();

The Composite Pattern

Pakt Laravel and Vue book