tony2001 Wed Jun 27 12:30:28 2007 UTC
Added files: (Branch: PHP_5_2)
/php-src/ext/spl/tests bug41692.phpt
Modified files:
/php-src NEWS
/php-src/ext/spl spl_array.c
Log:
MFH: fix #41692 (ArrayObject shows weird behaviour in respect to inheritance)
http://cvs.php.net/viewvc.cgi/php-src/NEWS?r1=1.2027.2.547.2.805&r2=1.2027.2.547.2.806&diff_format=u
Index: php-src/NEWS
diff -u php-src/NEWS:1.2027.2.547.2.805 php-src/NEWS:1.2027.2.547.2.806
--- php-src/NEWS:1.2027.2.547.2.805 Wed Jun 27 08:56:38 2007
+++ php-src/NEWS Wed Jun 27 12:30:27 2007
@@ -53,6 +53,8 @@
(Chris Jones, Tony)
- Fixed bug #41698 (float parameters truncated to integer in prepared
statements). (Ilia)
+- Fixed bug #41692 (ArrayObject shows weird behaviour in respect to
+ inheritance). (Tony)
- Fixed bug #41686 (Omitting length param in array_slice not possible).
(Ilia)
- Fixed bug #41685 (array_push() fails to warn when next index is already
http://cvs.php.net/viewvc.cgi/php-src/ext/spl/spl_array.c?r1=1.71.2.17.2.11&r2=1.71.2.17.2.12&diff_format=u
Index: php-src/ext/spl/spl_array.c
diff -u php-src/ext/spl/spl_array.c:1.71.2.17.2.11
php-src/ext/spl/spl_array.c:1.71.2.17.2.12
--- php-src/ext/spl/spl_array.c:1.71.2.17.2.11 Fri Apr 6 17:57:10 2007
+++ php-src/ext/spl/spl_array.c Wed Jun 27 12:30:28 2007
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: spl_array.c,v 1.71.2.17.2.11 2007/04/06 17:57:10 helly Exp $ */
+/* $Id: spl_array.c,v 1.71.2.17.2.12 2007/06/27 12:30:28 tony2001 Exp $ */
#ifdef HAVE_CONFIG_H
# include "config.h"
@@ -891,7 +891,7 @@
{
zval *object = getThis();
spl_array_object *intern;
- zval *array;
+ zval **array;
long ar_flags = 0;
char *class_name;
int class_name_len;
@@ -904,11 +904,15 @@
intern = (spl_array_object*)zend_object_store_get_object(object
TSRMLS_CC);
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|ls", &array,
&ar_flags, &class_name, &class_name_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Z|ls", &array,
&ar_flags, &class_name, &class_name_len) == FAILURE) {
php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC);
return;
}
+ if (Z_TYPE_PP(array) == IS_ARRAY) {
+ SEPARATE_ZVAL_IF_NOT_REF(array);
+ }
+
if (ZEND_NUM_ARGS() > 2) {
if (zend_lookup_class(class_name, class_name_len,
&pce_get_iterator TSRMLS_CC) == FAILURE) {
zend_throw_exception(spl_ce_InvalidArgumentException,
"A class that implements Iterator must be specified", 0 TSRMLS_CC);
@@ -920,25 +924,25 @@
ar_flags &= ~SPL_ARRAY_INT_MASK;
- if (Z_TYPE_P(array) == IS_OBJECT && (Z_OBJ_HT_P(array) ==
&spl_handler_ArrayObject || Z_OBJ_HT_P(array) == &spl_handler_ArrayIterator)) {
+ if (Z_TYPE_PP(array) == IS_OBJECT && (Z_OBJ_HT_PP(array) ==
&spl_handler_ArrayObject || Z_OBJ_HT_PP(array) == &spl_handler_ArrayIterator)) {
zval_ptr_dtor(&intern->array);
if (ZEND_NUM_ARGS() == 1)
{
- spl_array_object *other =
(spl_array_object*)zend_object_store_get_object(array TSRMLS_CC);
+ spl_array_object *other =
(spl_array_object*)zend_object_store_get_object(*array TSRMLS_CC);
ar_flags = other->ar_flags & ~SPL_ARRAY_INT_MASK;
}
ar_flags |= SPL_ARRAY_USE_OTHER;
- intern->array = array;
+ intern->array = *array;
} else {
- if (Z_TYPE_P(array) != IS_OBJECT && Z_TYPE_P(array) !=
IS_ARRAY) {
+ if (Z_TYPE_PP(array) != IS_OBJECT && Z_TYPE_PP(array) !=
IS_ARRAY) {
php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC);
zend_throw_exception(spl_ce_InvalidArgumentException,
"Passed variable is not an array or object, using empty array instead", 0
TSRMLS_CC);
return;
}
zval_ptr_dtor(&intern->array);
- intern->array = array;
+ intern->array = *array;
}
- if (object == array) {
+ if (object == *array) {
intern->ar_flags |= SPL_ARRAY_IS_SELF;
intern->ar_flags &= ~SPL_ARRAY_USE_OTHER;
} else {
@@ -946,12 +950,12 @@
}
intern->ar_flags |= ar_flags;
ZVAL_ADDREF(intern->array);
- if (Z_TYPE_P(array) == IS_OBJECT) {
- zend_object_get_properties_t handler = Z_OBJ_HANDLER_P(array,
get_properties);
+ if (Z_TYPE_PP(array) == IS_OBJECT) {
+ zend_object_get_properties_t handler = Z_OBJ_HANDLER_PP(array,
get_properties);
if ((handler != std_object_handlers.get_properties && handler
!= spl_array_get_properties)
|| !spl_array_get_hash_table(intern, 0 TSRMLS_CC)) {
php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC);
-
zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC,
"Overloaded object of type %s is not compatible with %s",
Z_OBJCE_P(array)->name, intern->std.ce->name);
+
zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC,
"Overloaded object of type %s is not compatible with %s",
Z_OBJCE_PP(array)->name, intern->std.ce->name);
return;
}
}
http://cvs.php.net/viewvc.cgi/php-src/ext/spl/tests/bug41692.phpt?view=markup&rev=1.1
Index: php-src/ext/spl/tests/bug41692.phpt
+++ php-src/ext/spl/tests/bug41692.phpt
--TEST--
Bug #41692 (ArrayObject shows weird behaviour in respect to inheritance)
--FILE--
<?php
class Bar extends ArrayObject {
private $foo = array( 1, 2, 3 );
function __construct()
{
parent::__construct($this->foo);
}
}
$foo = new Bar();
var_dump($foo);
$foo['foo'] = 23;
$bar = new Bar();
var_dump($bar);
echo "Done\n";
?>
--EXPECTF--
object(Bar)#%d (2) {
["foo":"Bar":private]=>
array(3) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
}
["storage":"ArrayObject":private]=>
array(3) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
}
}
object(Bar)#%d (2) {
["foo":"Bar":private]=>
array(3) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
}
["storage":"ArrayObject":private]=>
array(3) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
}
}
Done
--UEXPECTF--
object(Bar)#%d (2) {
[u"foo":u"Bar":private]=>
array(3) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
}
[u"storage":u"ArrayObject":private]=>
array(3) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
}
}
object(Bar)#%d (2) {
[u"foo":u"Bar":private]=>
array(3) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
}
[u"storage":u"ArrayObject":private]=>
array(3) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
}
}
Done
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php