0

グローバル変数の使用でいくつかのエラーに直面しています。グローバル スコープで $var を定義し、それを関数で使用しようとしましたが、そこではアクセスできません。より良い説明については、以下のコードを参照してください。

ファイル a.php:

<?php

  $tmp = "testing";

  function testFunction(){
     global $tmp;
     echo($tmp);
  }

この関数がどのように呼び出されるかについて少し説明します。

ファイル b.php:

<?php
  include 'a.php'
  class testClass{
    public function testFunctionCall(){
        testFunction();
    }
  }

上記の「b.php」は、次を使用して呼び出されます。

$method = new ReflectionMethod($this, $method);
$method->invoke();

現在、目的の出力は「テスト中」ですが、受信した出力は NULL です。

助けてくれてありがとう。

これは ReflectionMethod の使用と関係があると感じていますが、使用できない理由がわかりません。

4

1 に答える 1

0

これは私にとってはうまくいきます。[テスト済み] . また、参照渡しの使用を妨げているのは何ですか?

<?php
$tmp = "testing";

function testFunction(){
global $tmp;
echo($tmp);
}

class testClass
{
      public function testFunctionCall(){
          testFunction();
      }
}

$method = new ReflectionMethod($this, $method);
$method->testFunctionCall();
于 2013-09-19T13:04:18.387 に答える