PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
<?php
class 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}<br>second: {$b->two},<br>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
echo '<hr>';
$b = new B;
$b->output_text(); //prints out static::$text value
?>
Last edited by keevitaja on Fri Oct 30, 2009 12:21 pm, edited 1 time in total.
<?php
class A {
protected static $text;
public static function init($one = '', $two = '') {
$obj = new static;
$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}<br>second: {$b->two},<br>static text: {$b->static_text}<hr>"; //prints out the static_text
echo 'missing: ';
$b->output_text(); //doesn't print out the static::text value
echo '<hr>';
B::output_text(); //prints out static::$text value
echo '<hr>';
$b = new B;
$b->output_text(); //prints out static::$text value
?>