Alright, here it goes. This is what I am currently using, it works fine, but I got hung up on this idea...
class Estr {
public static function __callStatic ( $name, $arguments ) {
$class_vars = get_class_vars ( get_called_class ( ) );
if ( is_array ( $class_vars ) && sizeof ( $class_vars ) > 0 ) {
foreach ( $class_vars as $key => $value ) {
if ( strtolower ( $key ) == strtolower ( $name ) ) {
return $key;
}
}
}
}
}
class Relationship extends Estr {
public $alternate;
}
This allows me to call;
var_dump ( Relationship :: alternate ( ) ); // response "alternate"
All is well and great. However, when I started I wanted the following result;
var_dump ( Relationship :: alternate ); // response "alternate"
And I want my relationship class to be either;
class Relationship extends Estr {
public $alternate;
}
or
class Relationship extends Estr {
const alternate;
}
Where class Estr is handling returning the variable/constants name as the value, with a clean and OOP layout. (eg; 'const alternate = "alternate";' and 'const alternate = null;' are not desired.)
I attempted a few solutions, the closest I got to achieving the goal was attempting to catch the error of calling the undefined constant, while still returning the value. However, I still could not achieve the class hierarchy I desired.
Thanks for the noodle, enjoy the puzzle! XD
P.S. Or better yet, how can I static call a non-existing class constant and handle the error within that class? Eg; Relationship :: alternate Response; "error within class Relationship"
Is there a way to intercept the call for a "defined constant," even though by nature they should exist? (If not, this may be answered here; PHP => Call to non-existing class constants, way to handle?)