Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:739 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 56984 invoked from network); 6 Apr 2003 13:09:42 -0000 Received: from unknown (HELO moutng.kundenserver.de) (212.227.126.187) by pb1.pair.com with SMTP; 6 Apr 2003 13:09:42 -0000 Received: from [212.227.126.205] (helo=mrelayng.kundenserver.de) by moutng.kundenserver.de with esmtp (Exim 3.35 #1) id 1929u1-0002cZ-00 for internals@lists.php.net; Sun, 06 Apr 2003 15:09:41 +0200 Received: from [217.80.180.206] (helo=[217.80.180.206]) by mrelayng.kundenserver.de with asmtp (Exim 3.35 #1) id 1929u1-0003Vd-00 for internals@lists.php.net; Sun, 06 Apr 2003 15:09:41 +0200 To: internals@lists.php.net Content-Type: multipart/mixed; boundary="=-0xGAEJYo0AKhdfcJU/I5" Organization: Message-ID: <1049634596.25691.927.camel@localhost> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.2.1 Date: 06 Apr 2003 15:09:57 +0200 Subject: Suggestions: Built-in classes for PHP5 From: thekid@thekid.de (Timm Friebe) --=-0xGAEJYo0AKhdfcJU/I5 Content-Type: text/plain Content-Transfer-Encoding: 7bit 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 --=-0xGAEJYo0AKhdfcJU/I5 Content-Disposition: attachment; filename=zend_default_classes.c.diff Content-Type: text/x-patch; name=zend_default_classes.c.diff; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Index: Zend/zend_default_classes.c =================================================================== RCS file: /repository/ZendEngine2/zend_default_classes.c,v retrieving revision 1.3 diff -u -r1.3 zend_default_classes.c --- Zend/zend_default_classes.c 23 Mar 2003 17:18:31 -0000 1.3 +++ Zend/zend_default_classes.c 3 Apr 2003 18:14:29 -0000 @@ -22,6 +22,7 @@ #include "zend_API.h" zend_class_entry *default_exception_ptr; +zend_namespace *php_namespace_ptr; ZEND_FUNCTION(exception) { @@ -118,11 +119,16 @@ zend_class_entry default_exception; INIT_CLASS_ENTRY(default_exception, "exception", default_exception_functions); - default_exception_ptr = zend_register_internal_class(&default_exception TSRMLS_CC); + default_exception_ptr = zend_register_internal_class_in_ns(&default_exception, NULL, php_namespace_ptr, "php" TSRMLS_CC); } ZEND_API void zend_register_default_classes(TSRMLS_D) { + zend_namespace php_namespace; + + /* Register PHP namespace */ + INIT_NAMESPACE(php_namespace, "php"); + php_namespace_ptr= zend_register_internal_namespace(&php_namespace TSRMLS_C); zend_register_default_exception(TSRMLS_C); } --=-0xGAEJYo0AKhdfcJU/I5--