Closed Thread Icon

Topic awaiting preservation: Class help get instance name (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=31574" title="Pages that link to Topic awaiting preservation: Class help get instance name (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: Class help get instance name <span class="small">(Page 1 of 1)</span>\

 
Hustluz
Bipolar (III) Inmate

From:
Insane since: Jun 2003

posted posted 01-06-2010 18:37

Problem im trying to write reusable code that will automatically get the instance name.

example

code:
class Object() {
public static nulls = array(blah blah blah);

public static function fill_nulls($post, $object_name){
foreach(static::$nulls as $key => $val){
if($post[$val] == '' || !isset($post[$val])){
$$object_name->$key = "NULL";	
}
}	
}

}

$object = new Object();



instead of setting a variable to be the name of the object is there a way to dynamiclly get the name of the new object so if the name changes the code doesnt have too?

argo_navis
Nervous Wreck (II) Inmate

From:
Insane since: Apr 2008

posted posted 01-13-2010 14:25

Not sure what you are trying to achieve. You can get the class name http://php.net/manual/en/function.get-class.php

Else you should use custom getters/setters imo.
Declare a "holder" variable private and create public methods to access it, get value, set value.

??

« BackwardsOnwards »

Show Forum Drop Down Menu