|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2009-09-27 10:26 UTC] galaxy4public+php at gmail dot com
Description: ------------ The attached patch introduces a run-time check for the SPL extension instead of the compile-time one. This allows to build SPL as a shared extension (the corresponding changes to config.m4 are included in the patch as well). This work was sponsored by the WebEnabled (http://webenabled.com) project. Since there is no way to attach patches to bug reports I'm including it below: === --- php-5.2.5.orig/ext/spl/config.m4 2006-12-04 18:01:53 +0000 +++ php-5.2.5/ext/spl/config.m4 2008-04-07 05:53:55 +0000 @@ -26,7 +26,7 @@ CPPFLAGS=$old_CPPFLAGS AC_DEFINE_UNQUOTED(HAVE_PACKED_OBJECT_VALUE, $ac_result, [Whether struct _zend_object_value is packed]) AC_DEFINE(HAVE_SPL, 1, [Whether you want SPL (Standard PHP Library) support]) - PHP_NEW_EXTENSION(spl, php_spl.c spl_functions.c spl_engine.c spl_iterators.c spl_array.c spl_directory.c spl_sxe.c spl_exceptions.c spl_observer.c, no) + PHP_NEW_EXTENSION(spl, [php_spl.c spl_functions.c spl_engine.c spl_iterators.c spl_array.c spl_directory.c spl_sxe.c spl_exceptions.c spl_observer.c], $ext_shared) PHP_INSTALL_HEADERS([ext/spl], [php_spl.h spl_array.h spl_directory.h spl_engine.h spl_exceptions.h spl_functions.h spl_iterators.h spl_observer.h spl_sxe.h]) PHP_ADD_EXTENSION_DEP(spl, pcre, true) fi --- php-5.2.11.orig/ext/standard/array.c 2009-08-14 06:18:47 +0000 +++ php-5.2.11/ext/standard/array.c 2009-09-27 08:46:42 +0000 @@ -324,20 +324,22 @@ PHP_FUNCTION(count) RETURN_LONG (php_count_recursive (array, mode TSRMLS_CC)); break; case IS_OBJECT: { -#ifdef HAVE_SPL - /* it the object implements Countable we call its count() method */ - zval *retval; - - if (Z_OBJ_HT_P(array)->get_class_entry && instanceof_function(Z_OBJCE_P(array), spl_ce_Countable TSRMLS_CC)) { - zend_call_method_with_0_params(&array, NULL, NULL, "count", &retval); - if (retval) { - convert_to_long_ex(&retval); - RETVAL_LONG(Z_LVAL_P(retval)); - zval_ptr_dtor(&retval); + zend_class_entry **pce; + /* check whether the SPL extension available or not */ + if (zend_hash_find(EG(class_table), "countable", sizeof("Countable"), (void **) &pce) == SUCCESS) { + /* if the object implements Countable we call its count() method */ + zval *retval; + if (Z_OBJ_HT_P(array)->get_class_entry && instanceof_function(Z_OBJCE_P(array), *pce TSRMLS_CC)) { + zend_call_method_with_0_params(&array, NULL, NULL, "count", &retval); + if (retval) { + convert_to_long_ex(&retval); + RETVAL_LONG(Z_LVAL_P(retval)); + zval_ptr_dtor(&retval); + } + return; } - return; } -#endif + /* if not we return the number of properties (not taking visibility into account) */ if (Z_OBJ_HT_P(array)->count_elements) { RETVAL_LONG(1); === PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 30 08:00:01 2025 UTC |
Actually the patch changes 2 lines in ext/array.c and makes it possible to build SPL as a shared extension (all other code is already in place). In 5.3.0 somebody removed a couple of configuration lines from ext/spl/config.m4 and made it impossible to configure SPL with the configure script. I believe that this was done due to the fact that calls to SPL are all hardcoded dependencies. Frankly, I don't understand why hardcode things when the mechanism for dynamic loading is already here. Instead of unconditionally rely on things like: === if (Z_OBJ_HT_P(array)->get_class_entry && instanceof_function(Z_OBJCE_P(array), spl_ce_Countable TSRMLS_CC)) { === why don't you use something like: === if (zend_hash_find(EG(class_table), "countable", sizeof("Countable"), (void **) &pce) == SUCCESS) { if (Z_OBJ_HT_P(array)->get_class_entry && instanceof_function(Z_OBJCE_P(array), *pce TSRMLS_CC)) { === Then, you can: a) drop '#ifdef HAVE_SPL' around this blocks, since they will no longer strictly depend on SPL; b) it will be possible to build/load SPL dynamically (with no or little effort) Otherwise, what's the point of having "extensions" if they aren't extensions but an integral part of the interpreter and can't be loaded dynamically? What really missing in PHP is a good extension dependency mechanism (and, perhaps, auto extension loading), IMHO.