Php POO Flashcards
3 ways to call a static method (class Foo, method bar)
1. $foo = new Foo; $foo::bar(); 2. $foo = 'Foo' $foo::bar(); 3. Foo::bar();
Rules about method override
- Visibility: Same or less restrictiv
- Same number of required argument.
- Same signature (same type of arguments, same return value)
method __construct can be declared in … (3)
- class
- interface
- abstract class
Rules about constants declared in interface
Can not be overriden
Precedence order of trait and inheritance
class A{ function a(A) {}} trait T { function a(T) {}} class B extends A{ use T;} class C extends A{ use T; function a() {C}} C::a() -> C B::a() -> T A::a() -> A
How to access parent of class A which use trait T in T
In T, using “parent::” allows to access the parent of any class using the trait.
foreach of an object without the Iterable or the IteratorAgregate interface.
What happens?
Iterate through all public argument.
How to do a quick collection? (2)
- Implement IteratorAggregate and return the array wrapped in an ArrayIterator
- Implement Iterable and use the function current(), key(), reset(), next() in the method with the same names
How to do a quick collection? (2)
- Implement IteratorAggregate and return the array wrapped in an ArrayIterator
- Implement Iterable and use the function current(), key(), reset(), next() in the method with the same names
How need to be declared the __construct of a class inheriting from one declaring an abstract __construct?
For the first __construct in te hierarchy which is not abstract, the same as signature (same rules as method override). After, anyhow