The declaration var $b;
is PHP 4. PHP 5 allows it and it is equivalent to public $b;
.
However, it is deprecated and if you use a proper error reporting (error_reporting(E_ALL);
during development) you get a warning about it. You should use the PHP 5 visibility kewords instead.
Also, the declaration function repo($myvar)
is a PHP 4 constructor style, also accepted but deprecated. You should use the PHP 5 __constructor()
syntax.
You access $b
as static::$b
and this is not compatible with its declaration (equivalent, as I said above, with public $b
). If you want it to be a class property (this is what static
does) you have to declare it as a class property (i.e. public static $b
).
Putting everything together, the proper way to write your class is:
final class repo {
// public static members are global variables; avoid making them public
/** @var \Guzzle\Http\Client */
private static $b;
// since the class is final, "protected" is the same as "private"
/** @var \Guzzle\Http\Client */
protected $client;
// PHP 5 constructor. public to allow the class to be instantiated.
// $myvar is probably a \Guzzle\Http\Client object
public __construct(\Guzzle\Http\Client $myvar)
{
static::$b = $myvar;
// $this->b probably works but static::$b is more clear
// because $b is a class property not an instance property
$this->client = static::$b;
}
}