Results: 1578
Notes
  • Newest first
  • Oldest first
  • Newest first(All)
  • Oldest first(All)
An interface can extend another interface in the same way that a class can extend another class
Interface IBar {
    public function method3();
}

Interface IArray {
    public function method2();
}

Interface IFoo extends IBar, IArray {
    public function method1();
}

class class1 implements IFoo {
    public function method1() {
        
    }
    public function method2() {
        
    }
    // public function method3() {
        
    // }
}
Class
class1
implements
IFoo
interface which extends other two interfaces itself. Because the class has not implemented
method3
method (commented), then the following error will be generated:
Fatal error:  Class class1 contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (IBar::method3)
by Valeri Tandilashvili
3 years ago
0
PHP
OOP
2
Child class can not extend final class
final class A {
    final public static function who() {
        echo __CLASS__;
    }
}

class B extends A {
    
}

B::who();
Fatal error:
Class B may not inherit from final class (A)
by Valeri Tandilashvili
3 years ago
0
PHP
OOP
2
200 OK
- Standard response for successful HTTP requests
201 Created
- The request has been fulfilled, resulting in the creation of a new resource
204 No Content
- The server successfully processed the request and is not returning any content
304 Not Modified
- Indicates that the resource has not been modified since the version specified by the request headers If-Modified-Since or If-None-Match
400 Bad Request
- The server cannot or will not process the request due to an apparent client error (e.g., malformed request syntax, too large size, invalid request message framing, or deceptive request routing)
401 Unauthorized
- Similar to 403 Forbidden, but specifically for use when authentication is required and has failed or has not yet been provided. The response must include a WWW-Authenticate header field containing a challenge applicable to the requested resource
403 Forbidden
- The request was a valid request, but the server is refusing to respond to it. The user might be logged in but does not have the necessary permissions for the resource
404 Not Found
- The requested resource could not be found but may be available in the future. Subsequent requests by the client are permissible
409 Conflict
- Indicates that the request could not be processed because of conflict in the request, such as an edit conflict between multiple simultaneous updates
500 Internal Server Error
- A generic error message, given when an unexpected condition was encountered and no more specific message is suitable
by Valeri Tandilashvili
4 years ago
0
HTTP
2
GET
- Retrieves data from the server
HEAD
- Retrieves only headers (without the response body)
POST
- Submits data to the server (used to create resources)
PUT
- Updates/Replaces data on the server
PATCH
- Update/Modify data on the server (used to apply partial modifications to a resource)
DELETE
- Deletes data from the server
by Valeri Tandilashvili
4 years ago
0
HTTP
2
1xx - Informational
100
- Continue
101
- Switching Protocols
102
- Processing (WebDAV) ... 2xx - Success
200
- OK
201
- Created
202
- Accepted
204
- No Content
206
- Partial Content ... 3xx - Redirection
301
- Moved Permanently
304
- Not Modified
307
- Temporary Redirect
308
- Permanent Redirect ... 4xx - Client Error
400
- Bad Request
401
- Unauthorized
402
- Payment Required
403
- Forbidden
404
- Not Found
405
- Method Not Allowed
406
- Not Acceptable
407
- Proxy Authentication Required
408
- Request Timeout
409
- Conflict ... 5xx - Server Error
500
- Internal Server Error
501
- Not Implemented
502
- Bad Gateway
503
- Service Unavailable
504
- Gateway Timeout ...
by Valeri Tandilashvili
4 years ago
0
HTTP
2
If we use several
traits
in the same class, the traits must not have the same method declared
trait Laser {
    public function who() { 
        echo 'I am a Laser' . PHP_EOL; 
    }
}
trait Projector {
    public function who() { 
        echo 'I am a Laser' . PHP_EOL; 
    }
}
class Galaxy {
    use Laser;//, Projector;
    use Projector;
}
Fatal error:
Trait method who has not been applied, because there are collisions with other trait methods on Galaxy
by Valeri Tandilashvili
4 years ago
0
PHP
OOP
PHP official doc
2
trait
is kind of solution to the famous
multiple inheritance
problem in PHP. Using traits we can access methods from different traits that we use in our class
class Mobile {
    public function battery() {
        echo 'Battery: MB_06, MF_02, MF_00' . PHP_EOL;
    }
}
trait Laser {
    public function power() {
        echo 'Power: 10 mW' . PHP_EOL;
    }
}
trait Projector {
    public function range() {
        echo 'Range: 2 M' . PHP_EOL;
    }
}
class Galaxy extends Mobile {
    use Laser;
    use Projector;
}

$obj1 = new Galaxy;

$obj1->range();
$obj1->power();
$obj1->battery();
by Valeri Tandilashvili
4 years ago
0
PHP
OOP
PHP official doc
2
In this example we are not able to call
who()
method of the child class
B
from parent class
A
class A {
    public static function who() {
        echo __CLASS__;
    }
    public static function test() {
        self::who();
    }
}

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

B::test();
The code will call
who()
method of parent class and print its name
A
If we need
test()
to call
who()
method of child class
B
from parent class, then we can use
late static binding
technique. To achieve it, we use
static
keyword:
class A {
    public static function who() {
        echo __CLASS__;
    }
    public static function test() {
        static::who(); // Here comes Late Static Bindings
    }
}

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

B::test();
by Valeri Tandilashvili
4 years ago
0
PHP
OOP
PHP official doc
2
static variable in a function
There can be a static local variable in a function that is declared only once (on the first execution of a function) and can store its value between function calls
function foo()
{
   static $numOfCalls = 0;
   
   $numOfCalls++;
   echo "this function has been executed " . $numOfCalls . " times" . PHP_EOL;
}

foo();
foo();
foo();
After executing the ebove code,
$numOfCalls
static variable gets incremented and the following text is printed:
this function has been executed 1 times
this function has been executed 2 times
this function has been executed 3 times
by Valeri Tandilashvili
4 years ago
0
PHP
OOP
2
differences and similarities between static and constant
Differences:
constant can not be changed
static variable can not be accessed with the class object
dollar sign is needed to access static variable inside and outside of the class
constant name can not be a keyword, e.g. class (BUT: function, self, parent, static)
Similarities :
both of them are class members
both of them are accessible with "self" keyword inside the class
by Valeri Tandilashvili
4 years ago
0
PHP
OOP
2
Results: 1578