2011/6/2 Ilia Alshanetsky <i...@prohost.org>: > I like the idea of an error message when this happens, but as few > other people in the thread had mentioned, I think it should be a > warning (E_WARNING) because the conversion results in data loss > (content of the array is replaced with "Array" string).
My initial choice for E_NOTICE was based on _convert_to_string() which already used the E_NOTICE level. E_WARNING could make sense too, but I have the feeling that this should be part of a bigger review concerning E_NOTICE/E_WARNING errors related to conversion to be as much coherent as possible. Find below a short list of zend_error() calls made from bad conversion: Zend/zend.c: ZEND_API void zend_make_printable_zval(zval *expr, zval *expr_copy, int *use_copy) /* {{{ */ 282:zend_error(EG(exception) ? E_ERROR : E_RECOVERABLE_ERROR, "Object of class %s could not be converted to string", Z_OBJCE_P(expr)->name); Zend/zend_object_handlers.c: ZEND_API int zend_std_cast_object_tostring(zval *readobj, zval *writeobj, int type TSRMLS_DC) /* {{{ */ 1508:zend_error(E_NOTICE, "Object of class %s could not be converted to int", ce->name); 1517:zend_error(E_NOTICE, "Object of class %s could not be converted to double", ce->name); Zend/zend_operators.c: ZEND_API void convert_scalar_to_number(zval *op TSRMLS_DC) /* {{{ */ 244:zend_error(E_WARNING, "Cannot convert to ordinal value"); \ ZEND_API void convert_to_long_base(zval *op, int base) /* {{{ */ 375:zend_error(E_NOTICE, "Object of class %s could not be converted to int", Z_OBJCE_P(op)->name); 382:zend_error(E_WARNING, "Cannot convert to ordinal value"); ZEND_API void convert_to_double(zval *op) /* {{{ */ 435:zend_error(E_NOTICE, "Object of class %s could not be converted to double", Z_OBJCE_P(op)->name); 442:zend_error(E_WARNING, "Cannot convert to real value (type=%d)", Z_TYPE_P(op)); ZEND_API void _convert_to_string(zval *op ZEND_FILE_LINE_DC) /* {{{ */ 580:zend_error(E_NOTICE, "Array to string conversion"); 594:zend_error(E_NOTICE, "Object of class %s to string conversion", Z_OBJCE_P(op)->name); As you can notice ;) this is not uniformly handled, however, many of those line does not appear to be reachable according to http://gcov.php.net/. There is room for a general improvement here. Patrick -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php