0

PHP create_function を使用して、コンテンツがヒアドキュメント スタイルの文字列で定義されたラムバ スタイルの関数を作成しています。コードを Hostgator アカウントに移動するまでは、すべて問題ありませんでした。Hostgator 環境に関する何かが原因で、機能が完全に失敗しています。

ヒアドキュメントが正常に機能しているように見え、create_function が実行されているようです。しかし、関数自体が呼び出されると、すべてのローカル変数が未定義であると主張する大量のエラーがダンプされます! 私は困惑しています!これを前に見た人はいますか?コードは次のとおりです。

$func_code = <<<EOT
extract( shortcode_atts( array('style' => '','class' => '', 'id' => '', 'gutter' => 'm'), $atts ) );
$col_and_gutter = isset($gutter) ? 'needle-' . $gutter : 'needle-m';

switch ($gutter) {
    case 'ew': $gutter = 'col-extra-wide-gutter'; break;
    case 'w': $gutter = 'col-wide-gutter'; break;
    case 'm': $gutter = 'col-med-gutter'; break;
    case 'n': $gutter = 'col-narrow-gutter'; break;
    case 'none': $gutter = 'col-no-gutter'; break;
}

if ($id != '') $id = 'id="' . $id . '"';
if ($style != '') $style = 'style="' . $style . '"';
$returnval =  '<div ' . $id . ' ' . $style . ' class="col-responsive ' . $col_and_gutter . " " . $gutter . " " . $class . '">';

$returnval .= '<div class="g1"><div class="g2"><div class="g3">' . do_shortcode($content) . '</div></div></div>';
$returnval .= '</div>';
return $returnval;
EOT;            

$func_code = str_replace('needle', $shortcode, $func_code);
$func_handle = create_function('$atts,$content', $func_code); 
add_shortcode($shortcode, $func_handle);
add_shortcode($shortcode . '-n', $func_handle);
add_shortcode($shortcode . '-nn', $func_handle);

エラー出力は次のとおりです。

注意: 未定義の変数: 129 行目の /home3/ade207/public_html/wp-content/themes/armstrongparent/lib/shortcodes.php の atts

注意: 未定義の変数: col_and_gutter /home3/ade207/public_html/wp-content/themes/armstrongparent/lib/shortcodes.php の 129 行目

注意: 未定義の変数: 129 行目の /home3/ade207/public_html/wp-content/themes/armstrongparent/lib/shortcodes.php のガター

注意: 未定義の変数: 131 行目の /home3/ade207/public_html/wp-content/themes/armstrongparent/lib/shortcodes.php のガター

注意: 未定義の変数: 132 行目の /home3/ade207/public_html/wp-content/themes/armstrongparent/lib/shortcodes.php のガター

注意: 未定義の変数: 133 行目の /home3/ade207/public_html/wp-content/themes/armstrongparent/lib/shortcodes.php のガター

注意: 未定義の変数: 134 行目の /home3/ade207/public_html/wp-content/themes/armstrongparent/lib/shortcodes.php のガター

注意: 未定義の変数: 135 行目の /home3/ade207/public_html/wp-content/themes/armstrongparent/lib/shortcodes.php のガター

注意: 未定義の変数: 136 行目の /home3/ade207/public_html/wp-content/themes/armstrongparent/lib/shortcodes.php のガター

注意: 未定義の変数: 139 行目の /home3/ade207/public_html/wp-content/themes/armstrongparent/lib/shortcodes.php のガター

注意: 未定義の変数: 139 行目の /home3/ade207/public_html/wp-content/themes/armstrongparent/lib/shortcodes.php の id

注意: 未定義の変数: 139 行目の /home3/ade207/public_html/wp-content/themes/armstrongparent/lib/shortcodes.php の id

注意: 未定義の変数: 140 行目の /home3/ade207/public_html/wp-content/themes/armstrongparent/lib/shortcodes.php の id

注意: 未定義の変数: 140 行目の /home3/ade207/public_html/wp-content/themes/armstrongparent/lib/shortcodes.php のスタイル

注意: 未定義の変数: 140 行目の /home3/ade207/public_html/wp-content/themes/armstrongparent/lib/shortcodes.php のスタイル

注意: 未定義の変数: 141 行目の /home3/ade207/public_html/wp-content/themes/armstrongparent/lib/shortcodes.php のスタイル

注意: 未定義の変数: /home3/ade207/public_html/wp-content/themes/armstrongparent/lib/shortcodes.php の 141 行目の returnval

注意: 未定義の変数: 141 行目の /home3/ade207/public_html/wp-content/themes/armstrongparent/lib/shortcodes.php の id

注意: 未定義の変数: 141 行目の /home3/ade207/public_html/wp-content/themes/armstrongparent/lib/shortcodes.php のスタイル

注意: 未定義の変数: col_and_gutter /home3/ade207/public_html/wp-content/themes/armstrongparent/lib/shortcodes.php の 141 行目

注意: 未定義の変数: 141 行目の /home3/ade207/public_html/wp-content/themes/armstrongparent/lib/shortcodes.php のガター

注意: 未定義の変数: 142 行目の /home3/ade207/public_html/wp-content/themes/armstrongparent/lib/shortcodes.php のクラス

注意: 未定義の変数: /home3/ade207/public_html/wp-content/themes/armstrongparent/lib/shortcodes.php の 142 行目の returnval

注意: 未定義の変数: 143 行目の /home3/ade207/public_html/wp-content/themes/armstrongparent/lib/shortcodes.php のコンテンツ

注意: 未定義の変数: /home3/ade207/public_html/wp-content/themes/armstrongparent/lib/shortcodes.php の 144 行目の returnval

注意: 未定義の変数: /home3/ade207/public_html/wp-content/themes/armstrongparent/lib/shortcodes.php の 145 行目の returnval

解析エラー: /home3/ade207/public_html/wp-content/themes/armstrongparent/lib/shortcodes.php(148) の構文エラー、予期しない ')': 1 行目のランタイム作成関数

4

1 に答える 1

0

@通行人。ありがとう、それは私に問題を教えてくれました。

すべての $variables は空の空白領域でした!! これは、ヒアドキュメントが自動変数置換を行うためです。したがって、GoDaddy と Linode VPS では正常に機能したが、Hostgator では正常に機能しなかったのはなぜかと疑問に思う人もいるかもしれません。

Hostgator で壊れた理由は、最初にアップロードしたときに Heredoc 行がもともと Nowdoc だったためです。エラーが発生したので、一重引用符を削除して Heredoc に変更しました。私はまったく考えていなかったし、ばかげてこれが変数置換を開始することに気づかなかったので、関数コードの文字列リテラルのままではなく、すべての変数が null 文字列に置き換えられました。

明らかに、Hostgator は PHP 5.3 以降を実行していないため、Nowdoc は機能しません。つまり、スクリプトを変更して下位互換性を高める必要があるということです。すべての変数を醜いものとしてエスケープする必要があるかもしれません。

于 2013-07-24T04:21:31.080 に答える