Suggestions: Built-in classes for PHP5

php.internals

Timm Friebe

23 years ago
Hello, as you might know, the Zend Engine 2 features a built-in Exception class. The problem with a class named Exception is that no user-defined class named Exception may exist. Suggestion #1 is to make use of Andrei's API function zend_register_internal_class_in_ns and to move it to a namespace called "php". This can be accomplished with a simple patch to Zend/zend_default_classes.c (attached). Main motivation for this patch: Users having their own class Exception might want to extend it from Throwable, Object. Of course, they could put in into their own namespace, then having to specify it everywhere. It just seems nicer to me not to force users to do so. Those users who are completely content with the built-in exception could still a) import it import class Exception from php; or b) extend it as in class MyException extends php::Exception { } . Suggestion #2 extends the first and goes a bit farther, featuring three more internal classes, object, throwable and error. An implementation, a test script, its output and some initial documentation can be seen at http://sitten-polizei.de/php/zend_default_classes/ The sourcecode seen there also includes: * Checks on static calls to the class methods. At the moment, if a user called var_dump(Exception::getMessage());, it would lead to a segmentation fault (access to getThis() which is then NULL). * A version of var_export() that prints out the member access types such as public, private, and protected and recognizes static members. The toString() method uses this, for example. Comments welcome! - Timm

(Marcus Börger)

23 years ago
At 15:09 06.04.2003, Timm Friebe wrote:
>Hello, >as you might know, the Zend Engine 2 features a built-in Exception >class. The problem with a class named Exception is that no user-defined >class named Exception may exist.
That is the sense of built in classes.
>Suggestion #1 is to make use of Andrei's API function >zend_register_internal_class_in_ns and to move it to a namespace called >"php". This can be accomplished with a simple patch to >Zend/zend_default_classes.c (attached).
It is just the other way round. Put your used defined "exceptin" in a namespace. marcus

Timm Friebe

23 years ago
On Sun, 2003-04-06 at 15:52, Marcus Börger wrote:
> At 15:09 06.04.2003, Timm Friebe wrote: > >Hello, > >as you might know, the Zend Engine 2 features a built-in Exception > >class. The problem with a class named Exception is that no user-defined > >class named Exception may exist. > > That is the sense of built in classes.
Actually, I'd say the sense of built-in classes is the same as built-in functions: They're likely to be faster, they have some possibilities userland doesn't have and are a convenient to have. [...]
> It is just the other way round. Put your used defined "exceptin" in a > namespace.
Well, this is a unnecessary constraint on users, though. I know this is possible, I just don't see any reason on why the Zend Engine should have its built-in classes in the global namespace. Do you? - Timm

(Marcus Börger)

23 years ago
At 16:08 06.04.2003, Timm Friebe wrote:
>On Sun, 2003-04-06 at 15:52, Marcus Börger wrote: > > At 15:09 06.04.2003, Timm Friebe wrote: > > >Hello, > > >as you might know, the Zend Engine 2 features a built-in Exception > > >class. The problem with a class named Exception is that no user-defined > > >class named Exception may exist. > > > > That is the sense of built in classes. > >Actually, I'd say the sense of built-in classes is the same as built-in >functions: They're likely to be faster, they have some possibilities >userland doesn't have and are a convenient to have.
Exactly
>[...] > > It is just the other way round. Put your used defined "exceptin" in a > > namespace. > >Well, this is a unnecessary constraint on users, though. I know this is >possible, I just don't see any reason on why the Zend Engine should have >its built-in classes in the global namespace. Do you?
Yes, the default should be the default. And in this case it means when you don't have your own namspace specific crap the engine defaults to the builtin exception. And another one: Why should we make all users type some lines of code not needed (import class exception etc. pp)? marcus