tags:

views:

71

answers:

1
+1  Q: 

Error in PHP code

The error:

Parse error: syntax error, unexpected T_STRING, expecting T_VARIABLE in
 PSubscriptionFile.php on line 90; 

I think that public static _fromJSON should be public

static function _fromJSON 

but that give Fatal error:

Declaration of PSubscriptionFile::__construct() must be compatible with that of 
PuSHSubscriptionInterface::__construct() in PSubscriptionFile.php on line 9

The files: http://github.com/bobdia/PuSHSubscriber

I don't understand how to fix the error.Thanks!

+11  A: 

You wrote

public static _fromJSON($data) {

instead of

public static function _fromJSON($data) {

The Fatal Error you get when you fix this is because your Constructor signature is not identical to the Constructor signature demanded by the interface PuSHSubscriptionInterface, which is defined at the bottom of your PuSHSubscriber.php

public function __construct(
    $domain, $subscriber_id, $hub, 
    $topic, $secret, $status = '', 
    $callback_url, $verify_token, $lease_time='');

while yours is

public function __construct(
    $domain, $subscriber_id, $hub, 
    $topic, $secret, $status = '', 
    $callback_url, $verify_token, $lease_time)

You made the last argument required. The note in the PHP Manual clearly says:

The class implementing the interface must use the exact same method signatures as are defined in the interface. Not doing so will result in a fatal error.

The point of an interface is have a contract. Classes implementing this contract may not alter the method signatures defined by the interface, because that would break the contract and defeat the purpose of the interface.

When the interface IFoo says you should have

public function fn($arg1, $arg2, $arg3 = NULL);

then every class implementing IFoo must implement the methods as defined in the interface.

Gordon