【Dev】PHPの開発中覚書

開発ざれごと

bookPHP05_12big

HDDを掃除していたら出てきたメモです。使えないが公開。

PHPに関する覚え書き

●画面が白くなって終わる
内部エラーにて強制終了されている
DB周りで(SQL文ミス等)確認。

●include_pathが反映されない
requireでエラーになる等。
PHPINFOで確認できる以下の項目は、このようになっている。
Master Value  =>  php.ini で設定された値
Local Value   =>  .htaccessやhttpd.conf等で設定を定義した場合
php_value
php_flag
php_admin_value
php_admin_flag
php.iniなのか、.htaccessなのか確認する。
include_pathが更新されている可能性がある。

●xdebug追加をphp.iniに記述するとき、zend_extension=か zend_extension_ts=なのかを見極めるには。
Filed under: Xdebug ? ne-zu @ 20:00:42
表題の、Xdebug追加時のモジュール指定、LinuxだったりWindowsだったりでも違ったりするので入れる度に迷ってしまっていた昨日にFarewell!(さらば!)です。
Eclipse用xdebug pluginについてくるマニュアルPDFに詳しく書かれていました。
If you don’t get this and you are sure the path is correct then you need to make
sure you have the correct entry for zend_extension in your PHP.INI file. When
you do PHP ?i or run a script with phpinfo() in it you need to look for 2 entries
Debug Build => no
Thread Safety => enabled
phpinfo()などで、以下の2行を確認すべし。
Debug Build => no
Thread Safety => enabled
The above output shows a non debug build that has thread safety so you should
use “zend_extension_ts".
Debug Build がnoで、Thread Safetyが有効の場合は、

zend_extension_ts

If thread safety was “disabled" then you should have the php.ini entry of
zend_extension=
thread safetyが無効の場合は、

zend_extension

if it was a debug build you need to have the entry
zend_extension_debug=
Debug buildが有効なら、

zend_extension_debug

If you are running a thread safe debug version of PHP, then your ini entry must
be of the form
zend_extension_debug_ts=
thread sageもdebugも有効なら

zend_extension_debug_ts

を使いなさい。
In summary the rule is (in the stated order)
1. start with “zend_extension"
2. if you have a debug build: Debug Build => yes , add “_debug"
3. if you have thread safety: Thread Safety => enabled , add “_ts"
まとめると、
1.zend_extensionに
2.もしデバッグビルドが有効なら、_debugを付けて、
3.もし、スレッドセーフが有効なら、_tsを付ける。

●デバッグ環境xdebugの利用
マニュアル
http://www.eclipse.org/pdt/documents/XDebugGuide.pdf
Apache conf/httpd.conf内のrewriteモジュールのコメントも外しておく

●PHPウェブアプリにてXdebugのブレーク利用法

(未確認)対象コードを、ウェブルートに置く必要があるらしい。
iniの場所を間違えないようにする事。PHPルートではない。
コンソールからなら、PHP -iにて確認できる。

●PHPコンソールアプリにてXdebugのブレーク利用法

なんとか成功。以下のiniを参考の事。
コンソール時は、余計なremote記述をコメントアウトにする必要があるらしい。

[XDebug]
;; Only Zend OR (!) XDebug
;Zend_extension_ts="C:xamppphpextphp_xdebug-2.0.2-5.2.5.dll"
extension_ts="C:/xampp/php/ext/php_xdebug52.dll"
zend_extension_ts="C:xamppphpextphp_xdebug.dll"
;xdebug.remote_enable=1
;xdebug.remote_host=192.168.111.1
;xdebug.remote_port=9000
xdebug.remote_handler="dbgp"
xdebug.profiler_enable=On
xdebug.profiler_output_dir="C:xampptmp"
xdebug.remote_mode=req
xdebug.manual_url=http://jp2.php.net
xdebug.collect_params=On
xdebug.dump.GET=*
xdebug.dump.POST=*

●xdebugが落ちる(大量ネスト対策)
xdebug.max_nesting_level = 20

●Unable to detect character encoding・・・
というWarningが表示される。
漢字関係

PHP.iniに、適切に設定する。
mbstring.language "neutral" PHP_INI_PERDIR PHP 4.3.0 から利用可能です。
mbstring.detect_order NULL PHP_INI_ALL PHP 4.0.6 から利用可能です。
mbstring.http_input "pass" PHP_INI_ALL PHP 4.0.6 から利用可能です。
mbstring.http_output "pass" PHP_INI_ALL PHP 4.0.6 から利用可能です。
mbstring.internal_encoding NULL PHP_INI_ALL PHP 4.0.6 から利用可能です。
mbstring.script_encoding NULL PHP_INI_ALL PHP 4.3.0 から利用可能です。
mbstring.substitute_character NULL PHP_INI_ALL PHP 4.0.6 から利用可能です。
mbstring.func_overload "0" PHP_INI_PERDIR PHP 4.2.0 から利用可能で、PHP <= 4.2.3 は PHP_INI_SYSTEM です。
mbstring.encoding_translation "0" PHP_INI_PERDIR PHP 4.3.0 から利用可能です。
変換にて表示される際は、(例以下)mbstring.detect_order=allなどで対処可能
mb_convert_encoding('ディレクトリー:’.$dt_dirreal,’SJIS’,’auto’);
これでも表示されるようなので、これでどうだろ。
mb_convert_encoding('ディレクトリー:’.$dt_dirreal,’SJIS’,"ASCII,JIS,UTF-8,EUC-JP,SJIS")
公式マニュアルでは、"auto"="ASCII,JIS,UTF-8,EUC-JP,SJIS"のはずなのだが、どうも違うらしい。

●正規表現
Perl系の正規表現preg_matchの方が高速。

#Perlの方が書きやすいし使いやすい。
if (preg_match("/^#/",$rec[3],$match)) {
$match配列にヒットパターンが入る仕組み。0はヒット全体。1?$1/$2に該当。
(?:)の書式は使えないようだ。

(|)が使えない!!これはヤバい
いや、使えるようだ。

●グローバル空間アクセス
function内より、グローバル定義変数へのアクセスにはGlobalにて変数を定義する必要がある。

●リファレンス参照引数
function側にて"のみ"定義する・・という風変わりな仕様。
呼び出し元は対策のしようがない。
&を付けて定義する。
Perlは全参照扱い。

●PHPによる数値or文字の判断
極まれに、これによる誤動作を見つける。他スクリプト系言語と同様に、$a=""+123;明示的にしなければいけない。

●Warning表示の場所
warningの場所は、ロジック的な問題が多く、その指し示す行番号は発生箇所でしかない<当り前
深くなると探し難いため、(テストコードであろうと)エラーチェッ

開発ざれごと

Posted by nabe