note 74802 added to function.get-class

From: Date: Fri, 27 Apr 2007 19:29:48 +0000
Subject: note 74802 added to function.get-class
Groups: php.notes 
Request: Send a blank email to php-notes+get-125931@lists.php.net to get a copy of this message
To matsgefvert dot se and Marc, I'm sorry but I'm still having a very difficult time understanding why you would want this behavior. I understand that you are generating some code for some persistent layer for database access. In your code example, Marc, you say that you would like the SomeTable::read() to return "SomeTable" when called from your client. Yet, at this point you *know* what the class name is. Even assuming you are generating this code automatically, you can simply generate your SomeTable class as such. <?php class PersistedObject { //... public static function read($table, $key){ // do some databasey stuff // with $table which is the table name return $table; } } class SomeTable extends PersistedObject { //... // make a copy in the child class public static function read($key){ $table = get_class(); return parent::read($table, $key); } } // this will now return "SomeTable" $someTableObject = SomeTable::read(1234); ?> I'm still failing to see how this would provide but a convenience for very rare & specific issues, at the cost of non-OOP behavior by allowing static methods to bind to objects instead of classes. One of the most common uses for get_class() is for debugging lines, for example: <?php class PersistedObject { //... public static function transaction($params){ // do some stuff if ($error_occurred){ echo "Error : WTFBBQ happened in " . get_class() . "::" . __FUNCTION__ . ". Time to get some coffee!"; } } class SomeTable extends PersistedObject { //... } SomeTable::transaction( $someParams ); ?> Now, when an error occurs inside the call to SomeTable::transaction(), we get incorrect error output. ---- Server IP: 64.71.164.2 Probable Submitter: 208.49.175.66 ---- Manual Page -- http://www.php.net/manual/en/function.get-class.php Edit -- https://master.php.net/note/edit/74802 Del: integrated -- https://master.php.net/note/delete/74802/integrated Del: useless -- https://master.php.net/note/delete/74802/useless Del: bad code -- https://master.php.net/note/delete/74802/bad+code Del: spam -- https://master.php.net/note/delete/74802/spam Del: non-english -- https://master.php.net/note/delete/74802/non-english Del: in docs -- https://master.php.net/note/delete/74802/in+docs Del: other reasons-- https://master.php.net/note/delete/74802 Reject -- https://master.php.net/note/reject/74802 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#125931) next »