/    Sign up×
Community /Pin to ProfileBookmark

defining variable as static when it is parameter

Hi, I have read the following post:
[url]http://net.tutsplus.com/tutorials/php/dependency-injection-huh/[/url]
in one of their code, when they call a function they mention when of the given parameter as static.
This is the code:

[code=php]// Also frequently called “Container”
class IoC {
/**
* @var PDO The connection to the database
*/
protected $db;

/**
* Create a new instance of Photo and set dependencies.
*/
public static newPhoto()
{
$photo = new Photo;
$photo->setDB(static::$db);
// $photo->setConfig();
// $photo->setResponse();

return $photo;
}
}

$photo = IoC::newPhoto();[/code]

I am talking about the line:

[code=php] $photo->setDB(static::$db);[/code]

what is the meaning of the static in the static::$db ?
I understand what is the meaning of static when you define class, a variable that is common to all the instance of that class.
But when you give it as a parameter, what is the meaning of mention it as static?
And if they do it like the following line:

[code=php] $photo->setDB($db);[/code]

what would be the different?

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@NogDogSep 09.2012 — As I understand it, the static:: keyword means to use the parent's value if/when a child class overrides it (PHP 5.3+):
[code=php]
<?php

class A
{
static protected $test="class A";
public function static_test()
{
echo static::$test; // Results class b
echo "<br />n";
echo self::$test; // Results class a
}
}

class B extends A
{
static protected $test="class B";
}

$obj = new B();
$obj->static_test();
?>
[/code]
×

Success!

Help @programAngel spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.7,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...