Self vs static in php

class A {
    public static function className(){
        echo __CLASS__;
    }

    public static function test(){
        self::className();
    }
}

class B extends A{
    public static function className(){
        echo __CLASS__;
    }
}

B::test();

This will print

A

In the other hand with static:: It has the expected behaviour

class A {
    public static function className(){
        echo __CLASS__;
    }

    public static function test(){
        static::className();
    }
}

class B extends A{
    public static function className(){
        echo __CLASS__;
    }
}


B::test();

This will print

B

What are magic functions?

  • Magic Methods¬†allow you to react to certain events when using these particular objects. This means when certain things happen to your object, you can define how it should react in that instance.
  • They start with double underscore
  • They are always defined inside of the class
  • They are never called directly

 

Examples:

__construct(), __destruct(), __call(), __callStatic(), __get(), __set(), __isset(), __unset(), __sleep(), __wakeup(), __toString(), __invoke(), __set_state(), __clone() and __debugInfo()

How to build a scalable application / api?

Scalability is the ability of a system network or process to handle a growing amount of work in a capable manner or its ability to be enlarged to accomodate that growth.

  • Use cloud that has ability to launch server on demand
  • Use load balancer (Amazon ELB, Rackspace Load Balancer)
  • Choose the right data storage (SQL or noSQL)
  • cache things
  • queue up everything that doesn’t need to be done synchronously, stats, logs notifications
  • Automate everything – you should be able to launch servers that self configure and get added to the resource pool automatically
  • run load tests
  • monitor everything – setup alerts
  • separate business logic into Service Oriented Architecture

More read here

Youtube video about Amazon AWS Services here