@@ -237,45 +237,64 @@ static bool create_driver_specific_pdo_object(pdo_driver_t *driver, zend_class_e
237237 if (ce_based_on_driver_name ) {
238238 if (instanceof_function (ce_based_on_called_object , ce_based_on_driver_name ) == false) {
239239 zend_throw_exception_ex (pdo_exception_ce , 0 ,
240- "%s::connect() cannot be called when connecting to the \"%s\" driver, "
241- "either %s::connect() or PDO::connect() must be called instead" ,
242- ZSTR_VAL (called_scope -> name ), driver -> driver_name , ZSTR_VAL (ce_based_on_driver_name -> name ));
240+ "%s::%s() cannot be called when connecting to the \"%s\" driver, "
241+ "either call %s::%s() or PDO::%s() instead" ,
242+ ZSTR_VAL (called_scope -> name ),
243+ new_object ? "connect" : "__construct" ,
244+ driver -> driver_name ,
245+ ZSTR_VAL (ce_based_on_driver_name -> name ),
246+ new_object ? "connect" : "__construct" ,
247+ new_object ? "connect" : "__construct"
248+ );
243249 return false;
244250 }
245251
246- /* A driver-specific implementation was instantiated via the connect() method of the appropriate driver class */
247- object_init_ex (new_object , ce_based_on_called_object );
252+ /* A driver-specific implementation is instantiated with the appropriate driver class */
253+ if (new_object ) {
254+ object_init_ex (new_object , ce_based_on_called_object );
255+ }
248256 return true;
249257 } else {
250258 zend_throw_exception_ex (pdo_exception_ce , 0 ,
251- "%s::connect() cannot be called when connecting to an unknown driver, "
252- "PDO::connect() must be called instead" ,
253- ZSTR_VAL (called_scope -> name ));
259+ "%s::%s() cannot be called when connecting to an unknown driver, "
260+ "call PDO::%s() instead" ,
261+ ZSTR_VAL (called_scope -> name ),
262+ new_object ? "connect" : "__construct" ,
263+ new_object ? "connect" : "__construct"
264+ );
254265 return false;
255266 }
256267 }
257268
258269 if (ce_based_on_driver_name ) {
259270 if (called_scope != pdo_dbh_ce ) {
260- /* A driver-specific implementation was instantiated via the connect method of a wrong driver class */
271+ /* A driver-specific implementation is instantiated of a wrong driver class */
261272 zend_throw_exception_ex (pdo_exception_ce , 0 ,
262- "%s::connect() cannot be called when connecting to the \"%s\" driver, "
263- "either %s::connect() or PDO::connect() must be called instead" ,
264- ZSTR_VAL (called_scope -> name ), driver -> driver_name , ZSTR_VAL (ce_based_on_driver_name -> name ));
273+ "%s::%s() cannot be called when connecting to the \"%s\" driver, "
274+ "either call %s::%s() or PDO::%s() instead" ,
275+ ZSTR_VAL (called_scope -> name ),
276+ new_object ? "connect" : "__construct" ,
277+ driver -> driver_name ,
278+ ZSTR_VAL (ce_based_on_driver_name -> name ),
279+ new_object ? "connect" : "__construct" ,
280+ new_object ? "connect" : "__construct"
281+ );
265282 return false;
266283 }
267284
268285 /* A driver-specific implementation was instantiated via PDO::__construct() */
269- object_init_ex (new_object , ce_based_on_driver_name );
270- } else {
286+ if (new_object ) {
287+ object_init_ex (new_object , ce_based_on_driver_name );
288+ }
289+ } else if (new_object ) {
271290 /* No driver-specific implementation found */
272291 object_init_ex (new_object , called_scope );
273292 }
274293
275294 return true;
276295}
277296
278- static void internal_construct (INTERNAL_FUNCTION_PARAMETERS , zend_object * object , zend_class_entry * current_scope , zval * new_zval_object )
297+ PDO_API void internal_construct (INTERNAL_FUNCTION_PARAMETERS , zend_object * object , zend_class_entry * current_scope , zval * new_zval_object )
279298{
280299 pdo_dbh_t * dbh = NULL ;
281300 bool is_persistent = 0 ;
@@ -343,12 +362,13 @@ static void internal_construct(INTERNAL_FUNCTION_PARAMETERS, zend_object *object
343362 RETURN_THROWS ();
344363 }
345364
346- if ( new_zval_object != NULL ) {
347- ZEND_ASSERT (( driver -> driver_name != NULL ) && "PDO driver name is null" );
348- if (!create_driver_specific_pdo_object (driver , current_scope , new_zval_object )) {
349- RETURN_THROWS ();
350- }
365+ ZEND_ASSERT (( driver -> driver_name != NULL ) && "PDO driver name is null" );
366+
367+ if (!create_driver_specific_pdo_object (driver , current_scope , new_zval_object )) {
368+ RETURN_THROWS ();
369+ }
351370
371+ if (new_zval_object ) {
352372 dbh = Z_PDO_DBH_P (new_zval_object );
353373 } else {
354374 dbh = php_pdo_dbh_fetch_inner (object );
@@ -497,7 +517,7 @@ static void internal_construct(INTERNAL_FUNCTION_PARAMETERS, zend_object *object
497517/* {{{ */
498518PHP_METHOD (PDO , __construct )
499519{
500- internal_construct (INTERNAL_FUNCTION_PARAM_PASSTHRU , Z_OBJ (EX (This )), EX ( This ). value . ce , NULL );
520+ internal_construct (INTERNAL_FUNCTION_PARAM_PASSTHRU , Z_OBJ (EX (This )), execute_data -> func -> common . scope , NULL );
501521}
502522/* }}} */
503523
0 commit comments