Skip to content

Update PDO parameter names #6272

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed

Update PDO parameter names #6272

wants to merge 3 commits into from

Conversation

nikic
Copy link
Member

@nikic nikic commented Oct 5, 2020

Second pass for PDO parameter name updates.

  • Use camel case.
  • Use &$var.
  • Use $column instead of $index. We have cases (both in PDO and other exts) where columns can also be given as strings.

@nikic nikic requested a review from kocsismate October 5, 2020 11:08

/** @return bool */
public function bindParam(string|int $param, mixed &$bind_var, int $type = PDO::PARAM_STR, int $max_length = 0, mixed $driver_options = null) {}
public function bindParam(string|int $param, mixed &$var, int $type = PDO::PARAM_STR, int $max_length = 0, mixed $driverOptions = null) {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You changed $driverOptions to $options in PDO::prepate(). is there any difference between the two use-cases?

(there is one one $max_length here)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For PDO::prepare(), the documentation says this:

This array holds one or more key=>value pairs to set attribute values for the PDOStatement object that this method returns. You would most commonly use this to set the PDO::ATTR_CURSOR value to PDO::CURSOR_SCROLL to request a scrollable cursor. Some drivers have driver-specific options that may be set at prepare-time.

So it seems that at least some of the supported options are generic PDO options, not driver-specific ones.

For $driverOptions on these APIs, it seems like the parameter is effectively unused. This sets the driver_params fields, but it is never actually used anywhere.


/** @return array */
public function fetchAll(int $mode = PDO::FETCH_BOTH, mixed ...$args) {}

/** @return mixed */
public function fetchColumn(int $index = 0) {}
public function fetchColumn(int $column = 0) {}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should update ext/mysqli $index usage to $column as well (e.g.

public function fetch_field_direct(int $index) {}
). mysqli uses "field" instead of column in its function names though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no idea what the best course of action would be :(


/** @return mixed */
public function fetchObject(?string $class = "stdClass", ?array $constructor_args = null) {}
public function fetchObject(?string $class = "stdClass", ?array $ctorArgs = null) {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason why this can't be $constructorArgs?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could also be a $constructorArgs. I prefer the shorter version a bit, but don't insist on it :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO args is a quite common abbreviation but ctor is much less common. I'd prefer $constructorArgs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants