@@ -1026,6 +1026,14 @@ static bool pdo_verify_fetch_mode(uint32_t default_mode_and_flags, zend_long mod
10261026}
10271027/* }}} */
10281028
1029+ /* Based on zend_is_class_instantiable() but doesn't check the visibility of the constructor */
1030+ static bool pdo_is_class_instantiable (const zend_class_entry * ce ) {
1031+ return
1032+ !(ce -> ce_flags & (ZEND_ACC_INTERFACE | ZEND_ACC_TRAIT | ZEND_ACC_EXPLICIT_ABSTRACT_CLASS | ZEND_ACC_IMPLICIT_ABSTRACT_CLASS | ZEND_ACC_ENUM ))
1033+ && (!ce -> constructor || !zend_is_non_instantiable_constructor (ce -> constructor ))
1034+ ;
1035+ }
1036+
10291037/* {{{ Fetches the next row and returns it, or false if there are no more rows */
10301038PHP_METHOD (PDOStatement , fetch )
10311039{
@@ -1088,7 +1096,7 @@ PHP_METHOD(PDOStatement, fetchObject)
10881096 ce = zend_standard_class_def ;
10891097 }
10901098
1091- if (UNEXPECTED (!zend_is_class_instantiable (ce ))) {
1099+ if (UNEXPECTED (!pdo_is_class_instantiable (ce ))) {
10921100 zend_argument_value_error (1 , "Class \"%s\" cannot be instantiated" , ZSTR_VAL (ce -> name ));
10931101 RETURN_THROWS ();
10941102 }
@@ -1196,7 +1204,7 @@ PHP_METHOD(PDOStatement, fetchAll)
11961204 } else {
11971205 fetch_class = zend_standard_class_def ;
11981206 }
1199- if (UNEXPECTED (!zend_is_class_instantiable (fetch_class ))) {
1207+ if (UNEXPECTED (!pdo_is_class_instantiable (fetch_class ))) {
12001208 zend_throw_error (NULL , "Cannot instantiate an object of class %s" , ZSTR_VAL (fetch_class -> name ));
12011209 RETURN_THROWS ();
12021210 }
@@ -1716,7 +1724,7 @@ bool pdo_stmt_setup_fetch_mode(pdo_stmt_t *stmt, zend_long mode, uint32_t mode_a
17161724 zend_argument_type_error (arg1_arg_num , "must be a valid class" );
17171725 return false;
17181726 }
1719- if (UNEXPECTED (cep -> constructor == NULL )) {
1727+ if (UNEXPECTED (! pdo_is_class_instantiable ( cep ) )) {
17201728 zend_throw_error (NULL , "Cannot instantiate an object of class %s" , ZSTR_VAL (cep -> name ));
17211729 return false;
17221730 }
0 commit comments