sb3108sa / phpbrowscap

Automatically exported from code.google.com/p/phpbrowscap
GNU Lesser General Public License v2.1
0 stars 0 forks source link

parse_ini_file in PHP 5.3 #11

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
The function browscap uses for reading the ini file (http://se2.php.net/
manual/en/function.parse-ini-file.php) has been changed in PHP 5.3 so that 
by default it actually parses (interprets) the content. That chokes up 
when it reaches a header line with brackets like "[Mozilla/2.0 
(compatible; Ask Jeeves)]".

What is the expected output? What do you see instead?
  Expected output: Array with data for all browsers defined in 
browscaps.ini
  Seen instead: empty Array.

What version of the product are you using? On what operating system?
  Browscap-php5-r17.zip
  PHP 5.3
  Linux

Please provide any additional information below.
  Fix: Line 309 replaced by:
if (version_compare(phpversion(), '5.3.0', '>=')) {
        $browsers = parse_ini_file($ini_path, true, INI_SCANNER_RAW);
} else {
        $browsers = parse_ini_file($ini_path, true);
}

Original issue reported on code.google.com by sebastia...@gmail.com on 2 Sep 2009 at 7:39

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
The above fix, by itself, does not address this issue!!!
Using "INI_SCANNER_RAW" converts false to a string, rather than a boolean.

The work-around is change ~line 354 from:
$browser[$key] = $value;
to:
switch($value){
 case 'true':
  $browser[$key] = true;
 break;
 case 'false':
  $browser[$key] = false;
 break;
 default:
  $browser[$key] = $value;                      
}

Original comment by eric.caron on 2 Sep 2009 at 3:17

GoogleCodeExporter commented 8 years ago
Well, the fix did address MY issue! :-) Which was getting anything out at all. 
My 
application does not use the Boolean capability info yet, so that shortcoming 
had 
gone under my radar so far. (If this was working before, then previous PHP 
versions 
must have parsed values but not section names.)
Thanks for the heads up, Eric.

Original comment by sebastia...@gmail.com on 2 Sep 2009 at 3:32

GoogleCodeExporter commented 8 years ago
I've submitted this as a bug to PHP, please give it some attention & love at
http://bugs.php.net/bug.php?id=49443

Original comment by eric.caron on 2 Sep 2009 at 3:53

GoogleCodeExporter commented 8 years ago
Done.
Good on you, Eric

Original comment by sebastia...@gmail.com on 2 Sep 2009 at 6:24

GoogleCodeExporter commented 8 years ago
Update: The problem lies actually in the semicolon, which in 5.3 is interpreted 
as a 
comment delimiter even inside the header, disabling the closing square bracket 
].
I've submitted this as a new bug to PHP, please give your support at
http://bugs.php.net/bug.php?id=49461

Original comment by sebastia...@gmail.com on 4 Sep 2009 at 6:13

GoogleCodeExporter commented 8 years ago
It better to use the already provided constant PHP_VERSION instead of 
phpversion()

if (version_compare(PHP_VERSION, '5.3.0')=='ge') {
    $browsers = parse_ini_file($ini_path, true, INI_SCANNER_RAW);
}else{
    $browsers = parse_ini_file($ini_path, true);
}

Original comment by oc3...@gmail.com on 8 Sep 2009 at 7:41

GoogleCodeExporter commented 8 years ago
Not a bad idea, though comparison with the string 'ge' won't work; 
version_compare 
returns -1, 0 or 1 by default, or true/false if used with the opt. operator.
So you either have to say
  if (version_compare(PHP_VERSION, '5.3.0')>=0) {...}
or as I did above
  if (version_compare(PHP_VERSION, '5.3.0', '>=')) {...}
I wish we soon can change the operator to '=='...

Original comment by sebastia...@gmail.com on 8 Sep 2009 at 7:54

GoogleCodeExporter commented 8 years ago
yes sorry,i gave untested code from what i remembered, after taking a look at 
the 
manual it turns out you're right. The `ge`(the same as >=) used by me at the 
comparison 
is instead to be used as the third optional operator.
== operator makes more sense but the third optional param is ok also :)

Original comment by oc3...@gmail.com on 9 Sep 2009 at 5:12

GoogleCodeExporter commented 8 years ago
Yes, it worked! Thank you!

if (version_compare(PHP_VERSION, '5.3.0') >= 0) {
        $browsers = parse_ini_file($ini_path, true, INI_SCANNER_RAW);
}else{
        $browsers = parse_ini_file($ini_path, true);
}

Original comment by cem...@gmail.com on 30 Sep 2009 at 7:17

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
I think this fix should go into the class itself instead of being only available
here. I just lost several hours trying to figure out what was wrong with the 
Browscap
class since it always returned an empty array. Turns out I have PHP 5.3.1 which 
is
affected by this problem. It is likely that more people will stumble upon this 
issue
since if affects all 5.3 versions so far and there is no exception or error 
returned,
so it's hard to figure out what the problem is. I believe this is a serious bug.
Apart from that, excelent class!!

Original comment by dev...@iol.pt on 19 Apr 2010 at 3:28

GoogleCodeExporter commented 8 years ago
@13, agreed.  Is anyone maintaining the code here?

Original comment by triplepoint on 27 Apr 2010 at 7:30

GoogleCodeExporter commented 8 years ago
@13, agreed. the fix should be included in release. after ubuntu upgrade, i 
have also 
spent few hours on figuring out what's the problem.

Original comment by schkov...@gmail.com on 4 May 2010 at 6:46

GoogleCodeExporter commented 8 years ago
Be sure to empty your cache after applying the patch suggested by oc3ans.

Original comment by tedmaste...@gmail.com on 6 Jul 2010 at 11:51

GoogleCodeExporter commented 8 years ago
Finally, after quite 1 year, the fix is committed in the github repository.

Sorry to all who waited for this to happen soon. 

Original comment by st.jonat...@gmail.com on 11 Jul 2010 at 1:53

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
Hi guys,

I've applied every upgrade that's been described in this doc and I still get an 
empty array.  Help?

Original comment by popamo...@gmail.com on 23 Sep 2010 at 9:24

Attachments:

GoogleCodeExporter commented 8 years ago
Hi guis,
I am repair (I see old bug) in method updateCache() in different php version 
(5.2.XX / 5.3.XX) in function parse_ini_file, see attach file

Original comment by geniv.ra...@gmail.com on 13 Jan 2011 at 10:43

Attachments:

GoogleCodeExporter commented 8 years ago
http://code.google.com/p/phpbrowscap/ isn't the announcement big enough?

Let me know on github if it is still not working for you

Original comment by st.jonat...@gmail.com on 13 Jan 2011 at 10:46

GoogleCodeExporter commented 8 years ago
I just want to make it clear that after upgrading my Browscap.php to the latest 
in the github repo, I was still getting an empty array. It took me a few but I 
ended up deleting both the cache.php and browscap.php file and letting it 
generate new ones. That solved my problem, for whatever reason all the arrays 
in cache.php were empty. 

I am only posting this here also since some people may check this, just wanted 
to stop further comments since it wasn't clear, comment #16 suggests deleting 
the cache but didn't really explain that it would solve the problems of empty 
arrays. Some people need extra prodding :P

Original comment by trippin7464 on 20 Mar 2011 at 3:18