<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>横浜鯖缶日誌 &#187; バグ</title>
	<atom:link href="http://pandora-lab.com/tag/%e3%83%90%e3%82%b0/feed/" rel="self" type="application/rss+xml" />
	<link>http://pandora-lab.com</link>
	<description>なんとも地味な日々の作業記録</description>
	<lastBuildDate>Fri, 05 Feb 2010 19:08:30 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>ja</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Net_UserAgent_Mobile のバグについて</title>
		<link>http://pandora-lab.com/2010/02/04/net_useragent_mobile-%e3%81%ae%e3%83%90%e3%82%b0%e3%81%ab%e3%81%a4%e3%81%84%e3%81%a6/</link>
		<comments>http://pandora-lab.com/2010/02/04/net_useragent_mobile-%e3%81%ae%e3%83%90%e3%82%b0%e3%81%ab%e3%81%a4%e3%81%84%e3%81%a6/#comments</comments>
		<pubDate>Thu, 04 Feb 2010 12:27:47 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[バグ]]></category>

		<guid isPermaLink="false">http://pandora-lab.com/?p=144</guid>
		<description><![CDATA[携帯のユーザエージェントから様々な情報を引き出すことのできるPEAR::Net_UserAgent_Mobile
とても便利で利用させてもらってます。
結構ながいこと地味な開発が続いて、2009年にstableとなったんだけど、まだ致命的なバグがある。
例えば下記のスクリプト

&#60;?
require_once('Net/UserAgent/Mobile.php');
$user_agent = 'DoCoMo/2.0 N900iS(c100;TB;W24H12)';
$agent = Net_UserAgent_Mobile::factory($user_agent);
print "キャリア: ".$agent-&#62;getCarrierLongName()."\n";
print "機種:".$agent-&#62;getModel();
?&#62;

ユーザエージェントを

$user_agent='Vodafone/1.0/V705SH (compatible; Y!J-SRD/1.0; http://help.yahoo.co.jp/help/jp/search/indexing/indexing-27.html)';

に変えると

Fatal error: Call to undefined function:  getcarrierlongname()

とエラーになってしまう。
自分で解析できないユーザーエージェントだと、無視せずにエラーを返して強制終了してしまう。
このバグは致命的。先々未知のユーザエージェントは続々と登場するわけで、その度にエラーが出ることになってしまう。
調べてみると、かなりの人が同じ症状で困っているし作者にバグ報告もされているが、その場しのぎで根本的な問題が修正がされることなくstableとなった。
対処方法

&#60;?
require_once('Net/UserAgent/Mobile.php');
$user_agent='Vodafone/1.0/V705SH (compatible; Y!J-SRD/1.0; http://help.yahoo.co.jp/help/jp/search/indexing/indexing-27.html)';
$agent = Net_UserAgent_Mobile::factory($user_agent);
if (method_exists($agent,'isNonMobile')){
	print "キャリア: ".$agent-&#62;getCarrierLongName()."\n";
	print "機種:".$agent-&#62;getModel();
}

のように

if (method_exists($agent,'isNonMobile')){
～
}

でラップしてスルーさせればOK
]]></description>
			<content:encoded><![CDATA[<p>携帯のユーザエージェントから様々な情報を引き出すことのできる<a href="http://pear.php.net/package/Net_UserAgent_Mobile" target="_blank">PEAR::Net_UserAgent_Mobile</a><br />
とても便利で利用させてもらってます。<br />
結構ながいこと地味な開発が続いて、2009年にstableとなったんだけど、まだ致命的なバグがある。</p>
<p>例えば下記のスクリプト</p>
<pre class="brush:php">
&#60;?
require_once('Net/UserAgent/Mobile.php');
$user_agent = 'DoCoMo/2.0 N900iS(c100;TB;W24H12)';
$agent = Net_UserAgent_Mobile::factory($user_agent);
print "キャリア: ".$agent-&#62;getCarrierLongName()."\n";
print "機種:".$agent-&#62;getModel();
?&#62;
</pre>
<p>ユーザエージェントを</p>
<pre>
$user_agent='Vodafone/1.0/V705SH (compatible; Y!J-SRD/1.0; http://help.yahoo.co.jp/help/jp/search/indexing/indexing-27.html)';
</pre>
<p>に変えると</p>
<pre>
Fatal error: Call to undefined function:  getcarrierlongname()
</pre>
<p>とエラーになってしまう。<br />
自分で解析できないユーザーエージェントだと、無視せずにエラーを返して強制終了してしまう。<br />
このバグは致命的。先々未知のユーザエージェントは続々と登場するわけで、その度にエラーが出ることになってしまう。</p>
<p>調べてみると、かなりの人が同じ症状で困っているし作者にバグ報告もされているが、その場しのぎで根本的な問題が修正がされることなくstableとなった。</p>
<h1>対処方法</h1>
<pre class="brush:php">
&#60;?
require_once('Net/UserAgent/Mobile.php');
$user_agent='Vodafone/1.0/V705SH (compatible; Y!J-SRD/1.0; http://help.yahoo.co.jp/help/jp/search/indexing/indexing-27.html)';
$agent = Net_UserAgent_Mobile::factory($user_agent);
if (method_exists($agent,'isNonMobile')){
	print "キャリア: ".$agent-&#62;getCarrierLongName()."\n";
	print "機種:".$agent-&#62;getModel();
}
</pre>
<p>のように</p>
<pre>
if (method_exists($agent,'isNonMobile')){
～
}
</pre>
<p>でラップしてスルーさせればOK</p>
]]></content:encoded>
			<wfw:commentRss>http://pandora-lab.com/2010/02/04/net_useragent_mobile-%e3%81%ae%e3%83%90%e3%82%b0%e3%81%ab%e3%81%a4%e3%81%84%e3%81%a6/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
