Home / Programming /
Notes taken at a conference - incomplete
method and properties
private is accessible only within classpublic is accessible anywhereprotected is available only to descendentconstants:
const PI = 3.14159;classname::methodMath::circularArea(5)class Person {
public $first;
public $last;
}
class Employee extends Person {
public $title;
}
accessing parent
parent::[methodnamenobrackets]final keyword
abstract class DataStore {
//These methods must be defined in the child class
abstract public function save();
abstract public function load($id);
}
abstract contract
interface Rateable {
public function rate( int $stars, $user);
public function getRating();
}
class StatusUpdate implements Rateable, Searchable {
protected $ratings[];
public function rate(int $stars, $user) {
$this->ratings[$user] = $stars;
}
public function search($query) {
// search stuff
}
}
trait Counter {
protected $counter;
public function increment() {
$counter ++;
}
public funciton getCounter() {
return $counter;
}
}
class MyCounter {
use Counter;
}
$counter = new MyCounter();
$counter->increment();
echo $counter->getCount(); //1
<?php
namespace WorkLibrary;
class Database {
//stuff
}
.....
<?php
namespace MyLibrary;
class Database {
// stuff
}
usage:
$db = MyLibrary\Database::connect();use MyLibrary\Database;
$db = Database::connect();use MyLibrary\Database as MyD;;
$model = new MyD();$images = new \DateTime();\ allows for sub-namespaces as a separator____construct() and __destruct()__set() and __get()this document last modified: May 12 2018 17:45
Home / Programming /