/    Sign up×
Community /Pin to ProfileBookmark

My small static variable not displaying :((((

My below programe won’t desplay ?(( huhuhuhuhuhuhuhuhu

[CODE]
<?php

class staticex
{

protected static $_lkg = 1.55587;

echo self::$_lkg;

}

?>
[/CODE]

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@iBeZiDec 04.2014 — You can't just echo something in a class declaration, you need to put it in a function

[code=php]
<?php


class staticex
{

protected static $_lkg = 1.55587;

public static function showWeight() {
echo self::$_lkg;
}


}

staticex::showWeight();
[/code]
Copy linkTweet thisAlerts:
@NogDogDec 04.2014 — Or, in this case it might make more sense to make it a constant (assuming it is, in fact, a constant value that would never need to be changed by the app):
[code=php]
<?php

class staticex
{
const LKG = 1.55587;
}

echo staticex::LKG;
[/code]
Copy linkTweet thisAlerts:
@gautamz07authorDec 05.2014 — Thanks Superhelpful !
×

Success!

Help @gautamz07 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 6.18,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...