Skip to content

Commit 012439b

Browse files
Ayeshnikic
authored andcommitted
FTP: Disallow direct FTPConnection construction
Similar to other resource to object migrations, `FTPConnection` class is not allowed to be constructed with `new FTPConnection`. Related to b4503fb. Closes GH-6533.
1 parent c6a8f20 commit 012439b

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

ext/ftp/php_ftp.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ static zend_object* ftp_object_create(zend_class_entry* ce) {
8282
return zobj;
8383
}
8484

85+
static zend_function *ftp_object_get_constructor(zend_object *zobj) {
86+
zend_throw_error(NULL, "Cannot directly construct FTPConnection, use ftp_connect() or ftp_ssl_connect() instead");
87+
return NULL;
88+
}
89+
8590
static void ftp_object_destroy(zend_object *zobj) {
8691
php_ftp_object *obj = ftp_object_from_zend_object(zobj);
8792

@@ -114,6 +119,7 @@ PHP_MINIT_FUNCTION(ftp)
114119

115120
memcpy(&ftp_object_handlers, &std_object_handlers, sizeof(zend_object_handlers));
116121
ftp_object_handlers.offset = XtOffsetOf(php_ftp_object, std);
122+
ftp_object_handlers.get_constructor = ftp_object_get_constructor;
117123
ftp_object_handlers.dtor_obj = ftp_object_destroy;
118124
ftp_object_handlers.clone_obj = NULL;
119125

ext/ftp/tests/ftp_constructor.phpt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--TEST--
2+
Attempt to instantiate an FTPConnection directly
3+
--SKIPIF--
4+
<?php
5+
require 'skipif.inc';
6+
--FILE--
7+
<?php
8+
9+
try {
10+
new FTPConnection();
11+
} catch (Error $ex) {
12+
echo "Exception: ", $ex->getMessage(), "\n";
13+
}
14+
--EXPECT--
15+
Exception: Cannot directly construct FTPConnection, use ftp_connect() or ftp_ssl_connect() instead

0 commit comments

Comments
 (0)