Skip to content
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

mysqli_sql_exception->getSqlState() #7746

Closed
nunoperalta opened this issue Dec 9, 2021 · 1 comment
Closed

mysqli_sql_exception->getSqlState() #7746

nunoperalta opened this issue Dec 9, 2021 · 1 comment

Comments

@nunoperalta
Copy link

nunoperalta commented Dec 9, 2021

Description

Hello,

About mysqli_sql_exception:
https://www.php.net/manual/en/class.mysqli-sql-exception.php

What's the point of:

protected string $sqlstate;

if we cannot access it?

I was also trying:

class mysqli_sql_exception_x extends \mysqli_sql_exception {
	public function getSqlState() : string {
		return $this->sqlstate;
	}
}

But then I get:

Class mysqli_sql_exception_x may not inherit from final class (mysqli_sql_exception)

Why doesn't \mysqli_sql_exception contain a getSqlState() method?

I see some workarounds with using Reflection, etc, but that's obviously not ideal.
At least we can still use mysqli_sqlstate, but still...

Thank you very much.

@damianwadley
Copy link
Member

The pattern with exceptions is to keep properties inaccessible and provide a getter method.

kamil-tekiela added a commit to kamil-tekiela/php-src that referenced this issue Dec 10, 2021
kamil-tekiela added a commit to kamil-tekiela/php-src that referenced this issue Dec 11, 2021
Create getter instead of making the property public
kamil-tekiela added a commit to kamil-tekiela/php-src that referenced this issue Dec 11, 2021
Create getter instead of making the property public
kamil-tekiela added a commit to kamil-tekiela/php-src that referenced this issue Dec 14, 2021
Create getter instead of making the property public
kamil-tekiela added a commit that referenced this issue Dec 30, 2021
* PHP-8.1:
  Fix bug GH-7746 (mysqli_sql_exception->sqlstate is inaccessible)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants
@nunoperalta @kamil-tekiela @damianwadley and others