diff --git a/reference/pdo/constants.xml b/reference/pdo/constants.xml index ae5e800c2572..af9d1a95d923 100644 --- a/reference/pdo/constants.xml +++ b/reference/pdo/constants.xml @@ -242,13 +242,20 @@ Specifies that the fetch method shall return a new instance of the - requested class, mapping the columns to named properties in the class. + requested class. - The magic - __set - method is called if the property doesn't exist in the requested class + The object is initialized by mapping the columns from the result set to + properties in the class. This process occurs before the constructor is + called, allowing the population of properties regardless of their + visibility or whether they are marked as readonly. If + a property does not exist in the class, the magic + __set() + method will be invoked if it exists; otherwise, a dynamic public property + will be created. However, when PDO::FETCH_PROPS_LATE + is also given, the constructor is called before the + properties are populated. diff --git a/reference/pdo/pdostatement/fetch.xml b/reference/pdo/pdostatement/fetch.xml index fd88c0371898..230380721edb 100644 --- a/reference/pdo/pdostatement/fetch.xml +++ b/reference/pdo/pdostatement/fetch.xml @@ -53,13 +53,18 @@ PDO::FETCH_CLASS: returns a new instance of the - requested class, mapping the columns of the result set to named - properties in the class, and calling the constructor afterwards, unless - PDO::FETCH_PROPS_LATE is also given. - If mode - includes PDO::FETCH_CLASSTYPE (e.g. PDO::FETCH_CLASS | - PDO::FETCH_CLASSTYPE) then the name of the class is - determined from a value of the first column. + requested class. The object is initialized by mapping the columns of + the result set to properties in the class. This occurs before the + constructor is called, allowing properties to be populated regardless + of their visibility or whether they are marked as readonly. + If a property does not exist in the class, the magic __set() + method will be invoked if it exists; otherwise, a dynamic public + property will be created. However, when PDO::FETCH_PROPS_LATE + is also given, the constructor is called before + the properties are populated. If mode includes + PDO::FETCH_CLASSTYPE (e.g. + PDO::FETCH_CLASS | PDO::FETCH_CLASSTYPE), the name + of the class is determined from the value of the first column. PDO::FETCH_INTO: updates an existing instance @@ -266,11 +271,11 @@ Reading backwards: Construction order - When objects are fetched via PDO::FETCH_CLASS the object + When objects are fetched via PDO::FETCH_CLASS, the object properties are assigned first, and then the constructor of the class is - invoked. If PDO::FETCH_PROPS_LATE is also given, this - order is reversed, i.e. first the constructor is called, and afterwards the - properties are assigned. + invoked. However, when PDO::FETCH_PROPS_LATE is also given, + this order is reversed, i.e. first the constructor is called, and + afterwards the properties are assigned.