Require 1 of 2 arguments in a method / function (one of two arguments optional)-Collection of common programming errors

If it can only use one or the other, then you have state. If you have state, you need polymorphism, or in this very small use-case, two different methods.

public function getById($id) {}
public function getByUrl($url) {}

That’s the end of it. That’s the best you can do for yourself.

if and only if you don’t know in advance which is being passed in, (like the case of user input), you can make a third method, to parse and validate the input string, determine which type it is, and call the appropriate method.