Skip to content
This repository has been archived by the owner on Nov 20, 2019. It is now read-only.

Should getSubdomains return an empty array if no subdomains found? #27

Closed
Rohaq opened this issue Jul 27, 2018 · 3 comments
Closed

Should getSubdomains return an empty array if no subdomains found? #27

Rohaq opened this issue Jul 27, 2018 · 3 comments
Milestone

Comments

@Rohaq
Copy link
Contributor

Rohaq commented Jul 27, 2018

As part of some validation requirements, I wanted to loop over subdomain labels, and since an array was the expected return of the getSubdomains() function, I assumed it would return an empty array if none were found.

Turns out it returns a null, meaning it broke any attempts to use it as the expected return type. I ended up working around this using a null coalescence like the following:

$subdomainLabels = $hostnameExtract->getSubdomains() ?? array();

So, should this function return an empty array by default? I'd personally prefer if it did, since it keeps the return type consistent - but others might have differing opinions.

@layershifter
Copy link
Owner

I fully agree with you, getSubdomains() should always return an array. Good enchantment for next major.

@layershifter layershifter added this to the 2.0 milestone Jul 31, 2018
@Rohaq
Copy link
Contributor Author

Rohaq commented Jul 31, 2018

Good stuff, it might also be worth digging around to see if there are any others that do the same.

@layershifter
Copy link
Owner

@Rohaq thank you, released in 2.0.0.

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

No branches or pull requests

2 participants