Skip to content

IMAP: Resource object constructor and stub #6534

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions ext/imap/php_imap.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,11 @@ static zend_object* imap_object_create(zend_class_entry* ce) {
return zobj;
}

static zend_function *imap_object_get_constructor(zend_object *zobj) {
zend_throw_error(NULL, "Cannot directly construct IMAPConnection, use imap_open() instead");
return NULL;
}

static void imap_object_destroy(zend_object *zobj) {
php_imap_object *obj = imap_object_from_zend_object(zobj);

Expand Down Expand Up @@ -483,6 +488,7 @@ PHP_MINIT_FUNCTION(imap)

memcpy(&imap_object_handlers, &std_object_handlers, sizeof(zend_object_handlers));
imap_object_handlers.offset = XtOffsetOf(php_imap_object, std);
imap_object_handlers.get_constructor = imap_object_get_constructor;
imap_object_handlers.dtor_obj = imap_object_destroy;
imap_object_handlers.clone_obj = NULL;

Expand Down
2 changes: 1 addition & 1 deletion ext/imap/php_imap.stub.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

/** @generate-function-entries */
class IMAPConnection {
final class IMAPConnection {

}

Expand Down
15 changes: 15 additions & 0 deletions ext/imap/tests/imap_constructor.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
--TEST--
Attempt to instantiate an IMAPConnection directly
--SKIPIF--
<?php
extension_loaded('imap') or die('skip imap extension not available in this build');
--FILE--
<?php

try {
new IMAPConnection();
} catch (Error $ex) {
echo "Exception: ", $ex->getMessage(), "\n";
}
--EXPECT--
Exception: Cannot directly construct IMAPConnection, use imap_open() instead
11 changes: 11 additions & 0 deletions ext/imap/tests/imap_final.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--TEST--
Check that IMAPConnection is declared final
--SKIPIF--
<?php
extension_loaded('imap') or die('skip imap extension not available in this build');
--FILE--
<?php

class T extends IMAPConnection {}
--EXPECTF--
Fatal error: Class T may not inherit from final class (IMAPConnection) in %s on line %d