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

fetchSingle returning mixed, how to approach? #31

Open
dakorpar opened this issue Jul 7, 2022 · 0 comments
Open

fetchSingle returning mixed, how to approach? #31

dakorpar opened this issue Jul 7, 2022 · 0 comments

Comments

@dakorpar
Copy link

dakorpar commented Jul 7, 2022

How to properly solve those?
I know it will allways be ?int, but since fetchSingle is marked as returning mixed I can't solve this. I wouldn't want to just skip those checks....

	public function getIdByKey(string $key): ?int
	{
		return $this->db->select('id')->from($this->table)->where('%n = %s', 'key', $key)->fetchSingle();
	}

ofcours, here is integer in some other query will be something else...

only thing I think off as correct would maybe be:

	public function getIdByKey(string $key): ?int
	{
		/** @var int|null $id */
		$id = $this->db->select('id')->from($this->table)->where('%n = %s', 'key', $key)->fetchSingle();
	}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant