mirror of
https://github.com/php/php-src.git
synced 2025-08-16 05:58:45 +02:00
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 b4503fbf88
.
Closes GH-6533.
This commit is contained in:
parent
c6a8f201b1
commit
012439b78e
2 changed files with 21 additions and 0 deletions
|
@ -82,6 +82,11 @@ static zend_object* ftp_object_create(zend_class_entry* ce) {
|
|||
return zobj;
|
||||
}
|
||||
|
||||
static zend_function *ftp_object_get_constructor(zend_object *zobj) {
|
||||
zend_throw_error(NULL, "Cannot directly construct FTPConnection, use ftp_connect() or ftp_ssl_connect() instead");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void ftp_object_destroy(zend_object *zobj) {
|
||||
php_ftp_object *obj = ftp_object_from_zend_object(zobj);
|
||||
|
||||
|
@ -114,6 +119,7 @@ PHP_MINIT_FUNCTION(ftp)
|
|||
|
||||
memcpy(&ftp_object_handlers, &std_object_handlers, sizeof(zend_object_handlers));
|
||||
ftp_object_handlers.offset = XtOffsetOf(php_ftp_object, std);
|
||||
ftp_object_handlers.get_constructor = ftp_object_get_constructor;
|
||||
ftp_object_handlers.dtor_obj = ftp_object_destroy;
|
||||
ftp_object_handlers.clone_obj = NULL;
|
||||
|
||||
|
|
15
ext/ftp/tests/ftp_constructor.phpt
Normal file
15
ext/ftp/tests/ftp_constructor.phpt
Normal file
|
@ -0,0 +1,15 @@
|
|||
--TEST--
|
||||
Attempt to instantiate an FTPConnection directly
|
||||
--SKIPIF--
|
||||
<?php
|
||||
require 'skipif.inc';
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
try {
|
||||
new FTPConnection();
|
||||
} catch (Error $ex) {
|
||||
echo "Exception: ", $ex->getMessage(), "\n";
|
||||
}
|
||||
--EXPECT--
|
||||
Exception: Cannot directly construct FTPConnection, use ftp_connect() or ftp_ssl_connect() instead
|
Loading…
Add table
Add a link
Reference in a new issue