PHP和libphonenumber:将字符串转换为PhoneNumber对象?

So I'm passing a phone number string to my PHP back-end. I'm trying to use Google's libphonenumber to perform a validation of the passed phone number.

Here is the string: "+447400123456" ($val)

$phoneUtil = \libphonenumber\PhoneNumberUtil::getInstance();
$phoneNumber = new \libphonenumber\PhoneNumber().setNationalNumber($val);
error_log(json_encode($phoneNumber));
$internationalFormatPhoneNumber = $phoneUtil->format($phoneNumber, \libphonenumber\PhoneNumberFormat::INTERNATIONAL);
error_log(json_encode($internationalFormatPhoneNumber));

Unfortunately, I keep getting

"local.ERROR: exception 'Symfony\Component\Debug\Exception\FatalErrorException' with message 'Call to undefined function App\Http\Controllers\setNationalNumber()'"

All I want to do is check if the passed string is a valid international phone number (including mobiles) before I store it in my database.

Can anyone help me with this? I'm struggling with the documentation and keep getting errors.

You are using a dot operator . instead of the correct object operator -> so you just need to replace the .setNationalNumber($val) to ->setNationalNumber($val).