note 85230 added to language.oop5.paamayim-nekudotayim
| From: | haprogathaprogszonedotnet at osu1 dot php dot net | Date: | Thu, 21 Aug 2008 11:14:49 +0000 |
| Subject: | note 85230 added to language.oop5.paamayim-nekudotayim | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-143704@lists.php.net to get a copy of this message | ||
Here's a problem I ran into. (on PHP 5.2.0)
I'm not sure if this is a bug or not but here is an example that gives unexpected results in my
opinion:
<?php
header('Content-type: text/plain');
abstract class SQLTable {
public static $tablename;
public static $columns;
public static function getData($where) {
// debug
var_dump(self::$tablename);
var_dump(self::$columns);
// implement return data as array from SQL query:
// "SELECT ".implode(', ', self::$columns)." FROM
".self::$tablename." WHERE ".$where
}
}
class MyTable extends SQLTable {
public static $tablename = 'mytable';
public static $columns = array(
'id',
'text',
);
}
$table = new MyTable();
$table->getData('id=1'); // Call #1
MyTable::getData('id=1'); // Call #2
?>
I would expect both of these calls to echo:
string(7) "mytable"
array(2) {
[0]=>
string(2) "id"
[1]=>
string(4) "text"
}
Instead I get:
NULL
NULL
If I redeclare the function getData in MyTable exactly as it is now declared in SQLTable, then the
example will work as expected. Do I really need to repeat this exact declaration in every class that
extends SQLTable to get this functionality?
I could also make it work when I removed all static keywords and replaced all "self::$var"
with "$this->var" but then they aren't static and Call #2 results in a fatal
error.
Is self:: supposed to work like this when extending classes? If so, then I see a need for a similar
keyword for example this:: that would use the values from the extending class.
----
Server IP: 80.81.171.181
Probable Submitter: 91.153.63.96
----
Manual Page -- http://www.php.net/manual/en/language.oop5.paamayim-nekudotayim.php
Edit -- https://master.php.net/note/edit/85230
Del: integrated -- https://master.php.net/note/delete/85230/integrated
Del: useless -- https://master.php.net/note/delete/85230/useless
Del: bad code -- https://master.php.net/note/delete/85230/bad+code
Del: spam -- https://master.php.net/note/delete/85230/spam
Del: non-english -- https://master.php.net/note/delete/85230/non-english
Del: in docs -- https://master.php.net/note/delete/85230/in+docs
Del: other reasons-- https://master.php.net/note/delete/85230
Reject -- https://master.php.net/note/reject/85230
Search -- https://master.php.net/manage/user-notes.php