PHP notices

globway
Posts: 1
Joined: Thu Jul 23, 2015 4:39 am

PHP notices

Postby globway » Mon Feb 22, 2016 2:29 am

We noticed that there is an error in de code of UcwebU3Handler.php on line 86 which causes Notices.

It's this piece of code which assumes there is an key "1" in the array, while its not:

Code: Select all

$significant_version = explode('.', $version);
if ($significant_version[0] !== null) {
	if ($significant_version[1] === 0) {
		$deviceID = 'generic_ms_phone_os'.$significant_version[0].'_subuaucweb';
	}
	else {
		$deviceID = 'generic_ms_phone_os'.$significant_version[0].'_'.$significant_version[1].'_subuaucweb';
	}

	if (in_array($deviceID, self::$constantIDs)) {
		return $deviceID;
	}
}
I have made a temporary fix by changing it into:

Code: Select all

if ( !array_key_exists(1, $significant_version )|| $significant_version[1] === 0) {
	$deviceID = 'generic_ms_phone_os'.$significant_version[0].'_subuaucweb';
}
else {
	$deviceID = 'generic_ms_phone_os'.$significant_version[0].'_'.$significant_version[1].'_subuaucweb';
}
En example useragent which triggered this notice this was:

Code: Select all

Mozilla/5.0 (Linux; U; Android 8.0; en-US; Windows Phone 8 Build/JDQ39) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 UCBrowser/10.8.0.718 U3/0.8.0 Mobile Safari/534.30
Then there is a notice in UcwebU3.php on line 58. Again an assumption is made that an array key exists while it does not:

Code: Select all

//iPhone U3K
else if (WURFL_Handlers_Utils::checkIfContains($userAgent, 'iPhone;')) {

	if (preg_match('/iPhone OS (\d+)(?:_(\d+))?(?:_\d+)* like/', $userAgent, $matches)) {
		$version = $matches[1].'.'.$matches[2];
		$prefix = "$version U3iPhone $ucb_version".WURFL_Constants::RIS_DELIMITER;
		return $prefix.$userAgent;
	}
}
I fixed it by using this code:

Code: Select all

$version = (array_key_exists( 1, $matches) ? $matches[1] : '').'.'.(array_key_exists( 2, $matches) ? $matches[2] : '');
The user agent which triggered this notice was:

Code: Select all

Mozilla/5.0 (iPhone; CPU iPhone OS 84 like Mac OS X; zh-CN) AppleWebKit/537.51.1 (KHTML like Gecko) Mobile/12H143 UCBrowser/10.3.0.547 Mobile
In my opinion the code should be errors free, no matter the severity of the error (e.g. notice or warning). I hope you can fix these problens.

aaronp
Posts: 242
Joined: Wed Dec 09, 2015 12:39 pm

Re: PHP notices

Postby aaronp » Mon Feb 22, 2016 3:07 pm

Hi,

Are you able to let me know which version of the OnSite PHP API you are currently using?

Thanks,

Aaron


Who is online

Users browsing this forum: No registered users and 3 guests