Skip to content

mysqli_sql_exception->getSqlState() #7746

Closed

Description

@nunoperalta

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.

Activity

  1. damianwadley commented on Dec 10, 2021

    @damianwadley
    Member

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

  2. added 2 commits that reference this issue on Dec 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions