LSB (PHP 5.3) problem with static value!


Posted on 16th Feb 2014 07:03 pm by admin

hello,

i'm having a problem. static::$text variable gets lost at some point. can someone please correct and explain it to me?
Line number On/Off| Expand/Contract <?phpclass A { protected static $text; public static function init($one = '', $two = '') { $obj = new self; $obj->one = $one; $obj->two = $two; $obj->static_text = static::$text; return $obj; } public function output_text() { echo 'here shoult be some static text: ' . static::$text; }} class B extends A { protected static $text = 'this is a static text under php 5.3';} $b = B::init('first', 'second'); echo "first: {$b->one}
second: {$b->two},
static text: {$b->static_text}<hr>"; //prints out the static_text $b->output_text(); //doesn't print out the static::text value echo '<hr>'; B::output_text(); //prints out static::$text value?>

No comments posted yet

Your Answer:

Login to answer
85 Like 40 Dislike
Previous forums Next forums
Other forums

LinkedList help
Ok so I just learned quickly about lists, so I have a not too hard project I think, but am having a

Server side $_SESSION
how does one keep the session completely server side. no cookies to the browser at all. i need this

Get ID from Database when Posting with a HTML Form
I have a form I am submitting to a MySql database. Each product has an ID # attached to it that auto

mr8m - reverse document
Friends,

I'm trying to reverse a document held by MIRO, but it reports the message balan

str_replace help
Hey there,

I'm a PHP newb, I'm having troubles with the str_replace function. I want to clean

PDO returns erroneous columns from within pdt
Hi All,

This is a truly weird behavior:
When using a simple pdo fetch, erroneous columns a

need help in dynamic select menu in php
hi i have created a dynamic select menu using php. i have a problem in that which is when the user s

Beginner question regarding Array's
Hi everyone, the page im working on has an array of variable at the top...

Code: $define_li

How to give the privillege for triggers?
Hi,

How to give the privillage for triggers to particular user?

Please let me

Buggy registration system
Hey, I just started scripting in PHP, and I ran into a few problems.
Code: <?php
includ

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash