私が抱えているこの非常識な問題について助けが必要です
URL からデータを取得するために Curl を使用している作成したクラスがあり、その情報を使用して $_GET の各変数に値を指定します。
だから私はクラスを持っていて、新しいファイルを使用して新しい関数に投稿されたアイテムの $name を取得していますが、フレーズ付き変数を新しい関数に入れるたびに、ここで NULL を取得します私のクラスの略です
class AppStore {
public $name;
public function getData() {
$requestUrl = self::APPSTORE_LOOKUP_URL . $this->appIdentity;
$ch = curl_init($requestUrl);
curl_setopt($ch, CURLOPT_URL, $requestUrl);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($ch, CURLOPT_REFERER, "");
curl_setopt($ch, CURLOPT_COOKIESESSION, true);
curl_setopt($ch, CURLOPT_USERAGENT, $this->iTunesUserAgent);
curl_setopt($ch, CURLOPT_ENCODING, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
$response = curl_exec($ch);
$errno = curl_errno($ch);
curl_close($ch);
$parsedResponse = json_decode($response, true);
if ($parsedResponse['resultCount'] == 1)
{
$parsedResponse = $parsedResponse['results'][0];
$this->name = $parsedResponse['trackName'];
require_once('func.ini.php'); // new function to save images etc
} else {
throw new AppStoreService_Exception("mInvalid data returned from the AppStore Web Service. Check your app ID, and verify that the Appstore is currently up.");
}
}
}
// This is the func.ini.php code
echo $parsedResponse['trackName']; // Works here output equals a Name like Baraka etc
function save_image($img){
$dirs = "data/Apps/".$name; // Gets the name of the ID in the appIdentity so we can use CURL to download images and move the images to new folder else it'll fail and won't move
$path = $dirs."ScreenShots";
$fullp = basename($img);
$fullpath = "$path/$fullp";
$something = $dirs.'ScreenShots'
var_dump($parsedResponse['trackName']); // Null same if i echo it i get a white page etc
/* Sample Code
$ch = curl_init ($img);
curl_setopt($ch, CURLOPT_URL,$img);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
*/
}
基本的に、新しい関数 save_image で appIdentity の名前を取得するためにクラスの変数を追加しようとしているかどうかがわかれば、それは null になり、どうすれば $this-> を返すことができるかわかりません名前 ($parsedResponse['trackName']) は、新しい関数などですべて使用するためにグローバルになります。これは、クラスが public getData() を使用してから $this->name (getData()->name)
これは関数の側でのみ機能するため、関数がある場合、名前に設定された変数は関数の上にのみ値を持ちます。これが理解できることを願っています。
$this->name で返す必要があるかどうか、または getName() の下のクラスで新しいパブリック関数を作成しようとしたため、null も出力されるため、パブリック変数を設定できないため、わからない= ステートメントは、T_VARIABLE よりも T_FUNCTION を要求する try{} から catch(e) されるためです。つまり、public $name = $name; // エラー public $name = 'Test'; // 動作する '{$name}' 動作しない
class Test {
public $test = 'Help me out please!';
function GetMe() {
echo $this->test;
}
}
$open = new Test;
echo $open->GetMe(); // Outputs "Help me out please"
/* 変数ではできません :( ig $this->name / $parsedResponse['trackName'] */
誰かが私を助けることができれば、私は大歓迎です