Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » PHP
  • » RFC: about class names as values [RSS Feed]

#1 Jan. 6, 2011 00:54:50

Martin S.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

RFC: about class names as values


Hi all,

RFC: about class names as values

PHP uses class names as values, but only in a couple of places.
String constanst after the "new" or "instanceof" operator --correct me if
I'm missing others-- are treated as class names.

if( $obj instanceof MyClass ) {
// $obj is instanceof Bar/Foo/MyClass
}

but what happen if the class name is used on other places?

function newInstance($class) {
return new $class;
}

$obj = newInstance( MyClass ); // notice. undefined constant MyClass

so you have to end up by writting....

$obj = newInstance( '\Bar\Foo\MyClass' );

which lacks of any semantic, it's not a class name, it's just a string.

My idea is that PHP could include a constant on each class, a string with
the full qualified class name

echo MyClass::CLASS; // \Bar\Foo\MyClass
$obj = newInstance( MyClass::CLASS );

As the "CLASS" is currently a reserved word is guarantied that nobody is
using as it today.

What do you think about?

Martin Scotta

Offline

  • Root
  • » PHP
  • » RFC: about class names as values [RSS Feed]

Board footer

Moderator control

Enjoy the 17th of August
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support