diff --git a/ext/gd/gd.c b/ext/gd/gd.c index cdfaaeedaeb7f..4908ff8c01607 100644 --- a/ext/gd/gd.c +++ b/ext/gd/gd.c @@ -203,6 +203,19 @@ void php_gd_assign_libgdimageptr_as_extgdimage(zval *val, gdImagePtr image) php_gd_exgdimage_from_zobj_p(Z_OBJ_P(val))->image = image; } +#if GD_MAJOR_VERSION > 2 || (GD_MAJOR_VERSION == 2 && (GD_MINOR_VERSION > 2 || (GD_MINOR_VERSION == 2 && GD_RELEASE_VERSION >= 3))) +static zend_object *php_gd_clone(zend_object *zobj) +{ + gdImagePtr oldim = php_gd_exgdimage_from_zobj_p(zobj)->image; + gdImagePtr newim = gdImageClone(oldim); + zval znew; + + php_gd_assign_libgdimageptr_as_extgdimage(&znew, newim); + + return Z_OBJ(znew); +} +#endif + static void php_gd_object_minit_helper(void) { gd_image_ce = register_class_GdImage(); @@ -210,7 +223,11 @@ static void php_gd_object_minit_helper(void) /* setting up the object handlers for the GdImage class */ memcpy(&php_gd_image_object_handlers, &std_object_handlers, sizeof(zend_object_handlers)); - php_gd_image_object_handlers.clone_obj = NULL; +#if GD_MAJOR_VERSION > 2 || (GD_MAJOR_VERSION == 2 && (GD_MINOR_VERSION > 2 || (GD_MINOR_VERSION == 2 && GD_RELEASE_VERSION >= 3))) + php_gd_image_object_handlers.clone_obj = php_gd_clone; +#else + php_gd_image_object_handlers.clone_obj = NULL; +#endif php_gd_image_object_handlers.free_obj = php_gd_image_object_free; php_gd_image_object_handlers.get_constructor = php_gd_image_object_get_constructor; php_gd_image_object_handlers.compare = zend_objects_not_comparable; diff --git a/ext/gd/tests/gdimage_cloning.phpt b/ext/gd/tests/gdimage_cloning.phpt new file mode 100644 index 0000000000000..ed8b2021b478a --- /dev/null +++ b/ext/gd/tests/gdimage_cloning.phpt @@ -0,0 +1,26 @@ +--TEST-- +Checks that GdImage instances can be cloned from gd > 2.2.3 +--EXTENSIONS-- +gd +--SKIPIF-- + +--FILE-- + +--EXPECTF-- +bool(true) +bool(true) diff --git a/ext/gd/tests/gdimage_prevent_cloning.phpt b/ext/gd/tests/gdimage_prevent_cloning.phpt index 426f7d9c48f6c..fbf201f0fcc16 100644 --- a/ext/gd/tests/gdimage_prevent_cloning.phpt +++ b/ext/gd/tests/gdimage_prevent_cloning.phpt @@ -2,6 +2,8 @@ Checks that GdImage instances cannot be cloned --EXTENSIONS-- gd +--SKIPIF-- +=')) die("Skipped: GdImage is clonable from gd 2.2.3"); ?> --FILE--