Both sides previous revisionPrevious revisionNext revision | Previous revision |
rfc:improve_mysqli [2020/12/30 18:02] – Fix markdown dharman | rfc:improve_mysqli [2020/12/30 18:27] (current) – Grammar dharman |
---|
=== mysqli::init() is confusing, unnecessary, and not an alias of mysqli_init() === | === mysqli::init() is confusing, unnecessary, and not an alias of mysqli_init() === |
| |
Despite what the documentation says, ''mysqli::init()'' is not an OOP version of ''mysqli_init()''. In fact, such a claim makes absolutely no sense, given that ''mysqli_init()'' was meant to create an empty instance of mysqli without calling the connect method. In reality, ''mysqli::init()'' is just a thin wrapper for ''%%mysqli::__construct()%%'' with 0 arguments. Gicen the nonsensical nature of this method I am proposing to [[https://github.com/php/php-src/pull/6409|deprecate it in PHP 8.1]]. | Despite what the documentation says, ''mysqli::init()'' is not an OOP version of ''mysqli_init()''. In fact, such a claim makes absolutely no sense, given that ''mysqli_init()'' was meant to create an empty instance of mysqli without calling the connect method. In reality, ''mysqli::init()'' is just a thin wrapper for ''%%mysqli::__construct()%%'' with 0 arguments. Given the nonsensical nature of this method I am proposing to [[https://github.com/php/php-src/pull/6409|deprecate it in PHP 8.1]]. |
| |
The only valid use case for this method was in polymorphism, which can be replaced with a constructor. | The only valid use case for this method was in polymorphism, which can be replaced with a constructor. |
=== "new mysqli()" doesn't open a connection with 0 arguments === | === "new mysqli()" doesn't open a connection with 0 arguments === |
| |
At the moment PHP manual claims that all 6 parameters of ''%%mysqli::__construct()%%'' are optional with default values taken from INI settings. As you might have guessed that is not entirely true. The default values are in fact honoured, but at least 1 argument must be provided, even if that 1 argument is ''NULL''. If absolutely no arguments are passed, then ''%%mysqli::__construct()%%'' behaves as ''mysqli_init()''. What are the workarounds if I want to store all my configuration details in INI? | At the moment PHP manual claims that all 6 parameters of ''%%mysqli::__construct()%%'' are optional with default values taken from INI settings. As you might have guessed that is not entirely true. The default values are in fact honoured, but at least 1 argument must be provided, even if that 1 argument is ''NULL''. If absolutely no arguments are passed, then ''%%mysqli::__construct()%%'' behaves as ''mysqli_init()''. Here are the workarounds if you want to store all the configuration details in INI: |
| |
<code php> | <code php> |