spatie/url

Default constructor result is unexpected

nyamsprod opened this issue · 1 comments

I was trying to add this library to my URI test suite and I stumble into this rather odd bug:

var_dump(
    (string) (new Url('http://example.com')), //display the empty string ???
    (string) Url::fromString('http://example.com') //display 'http://example.com'
);

Maybe you should protect the constructor because this is unexpected at best.

PS: the test suite reveals more problem too.

Since the constructor explicitly doesn't accept any arguments (https://github.com/spatie/url/blob/master/src/Url.php#L36), and new Url() isn't documented anywhere, I don't really consider this unexpected.

I do agree that it would be better off to protect the constructor, however strictly speaking that would be a breaking change so I'm gonna hold off on it until a next major version.