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

Add return type of inherited methods from Iterator in VCardParser #208

Open
codeflow-biz opened this issue Oct 20, 2022 · 2 comments
Open

Comments

@codeflow-biz
Copy link

PHP8.1 (at least - did not test with PHP8.0) logs deprecated issues because the 5 inherited methods from the Iterator base class in VCardParser do not declare the return type:

[20-Oct-2022 12:29:54 Europe/Vienna] PHP Deprecated:  Return type of JeroenDesloovere\VCard\VCardParser::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in .\VCardParser.php on line 72
[20-Oct-2022 12:29:54 Europe/Vienna] PHP Deprecated:  Return type of JeroenDesloovere\VCard\VCardParser::next() should either be compatible with Iterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in .\VCardParser.php on line 84
[20-Oct-2022 12:29:54 Europe/Vienna] PHP Deprecated:  Return type of JeroenDesloovere\VCard\VCardParser::key() should either be compatible with Iterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in .\VCardParser.php on line 79
[20-Oct-2022 12:29:54 Europe/Vienna] PHP Deprecated:  Return type of JeroenDesloovere\VCard\VCardParser::valid() should either be compatible with Iterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in .\VCardParser.php on line 89
[20-Oct-2022 12:29:54 Europe/Vienna] PHP Deprecated:  Return type of JeroenDesloovere\VCard\VCardParser::rewind() should either be compatible with Iterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in .\VCardParser.php on line 67

Fix:
Add return type :mixed to methods current() and key(),
add return type :bool to method valid(),
add return type :void to methods rewind(), next().

@Xavlight
Copy link

Xavlight commented Feb 7, 2023

Same problem.

Do you have a solution?

Xav

@Xavlight
Copy link

Xavlight commented Feb 7, 2023

Hi,

I was able to fix the problem by naming the type of the functions public (void, mixed, bool).
No more deprecation messages.

Change in class : VCardParser.php

...
public function rewind(): void {
	$this->position = 0;
}

public function current(): mixed {
	if ($this->valid()) {
		return $this->getCardAtIndex($this->position);
	}
}

public function key(): mixed {
	return $this->position;
}

public function next(): void {
	$this->position++;
}

public function valid(): bool {
	return !empty($this->vcardObjects[$this->position]);
}
...

I just saw that the answer was already there, by [codeflow-biz].
But I didn't understand.

Xav

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