私がこれを行うとき:
{some code}
previouslyDeclaredFunction($variable);
{some code}
previousDeclaredFunction() を正常に動作させることができます。
しかし、新しい関数の中に入れると:
function newFunction($variable){
echo $variable; //see if var passes in properly
{some code}
previouslyDeclaredFunction($variable);
{some code}
}
..次に、次のように呼び出します。
newFunction($variable);
.. newFunction() 内から $variable を echo() できても、突然動作しなくなります。これは、newFunction() が適切に呼び出され、$variable が適切に渡されたことを意味します。どうやら、外側の関数全体を削除しない限り、内部の一部が機能しないようです。PreviouslyDeclaredFunction() は php スクリプトに含まれており、newFunction() 内から呼び出されますが、echo() が渡されていることを証明し、以前とまったく同じ値であることを証明しても、どういうわけか $variable の扱いが異なります。
編集(ここに本当のコードがあります):
$test_tag = "afro";
cacheBuilder($test_tag); //declaration of function
function cacheBuilder($test_tag) {
$images = array();
$tags = array();
$imagetype = 'Hair';
$per_page = 60;
$orderby_view = FALSE;
echo $test_tag; //this works so var is passed in fine
$tags2 = $test_tag;
$tags = explode(',', $test_tag);
if( count($tags) == 1 && strlen($tags[0]) == 0 ) $tags = array();
$tag_url = urlencode($tags2);
$cachename = dirname( __FILE__ ) . '/cache-fp/' . $imagetype . '-' . $per_page . '-' . $page . '-' . ($orderby_view ? 'by_view' : 'by_date') . $tag_url . '.json';
$detailurl = get_option('image_detail_url');
$detailurl .= (strstr($detailurl, '?') === FALSE ? '?' : '&');
$json = array();
$images = array();
$posts = get_pix($imagetype, array('per_page' => $per_page, 'page' => $page, 'tags' => $tags), $orderby_view);
foreach( $posts['attachments'] as $ii => $post ) {
$ta = array();
$meta = array();
$imagesrclight2 = array();
// BWP - Theater mode
$ta['detail_url'] = $detailurl . 'uid=' . $post->post_author . '&img_id=' . $post->ID . '&theater';
$meta = get_post_meta(get_the_ID(), 'image_tag', false);
$ta['image_tags'] = implode(' ', $meta);
$ta['attachment_image'] = wp_get_attachment_image($image->ID, 'thumbnail');
$imagesrclight2 = wp_get_attachment_image_src($image->ID, array(150, 150));
$ta['attachment_image_src'] = rawurlencode($imagesrclight2[0]);
$images[] = $ta;
}
file_put_contents($cachename, json_encode($images));
}
これは少し複雑で、Wordpress です。完全に混乱しないことを願っています。エラーはありませんが、外側の関数内で get_option や get_pix が失敗しているようです。生成されたjsonにはデータがありません。外側の関数を取り除くと、必要に応じてデータが取り込まれた json が得られます。