It is easier to make mistakes when typing a string. Using an undefined constant will throw a warning. It's not just a PHP thing. Regular API functions (i.e. of an OS) usually use numeric constants as well for parameters like this.

网友答案:

They use int .. and it more efficient that way because of Case Sensitivity , Spelling Mistakes , Parsing strings , Better for IDE , Error etc.

If you don't like constant you can just use int value

str_pad($test, 10, 0, 0) == str_pad( $test, 10, 0, STR_PAD_LEFT)

网友答案:

Notice that the type of $pad_type in the parameters is actually int. Passing ints is a lot faster than passing (then comparing) strings. So instead of passing a number into the function to tell it what to do, you pass the corresponding constant, making your code clearer. And if the PHP developers ever want to change it to pass strings instead of ints, they can do it without breaking any of your code, as long as you used the constants.