0
親クラス:PHP/Laravelの親クラス変数がnullである
<?php
namespace App\Services;
class RequestVariables {
protected static $keys_tour;
public static function init() {
self::$keys_tour = array_flip(['tour_type', 'city_from']);
}
}
子供クラス:私は第一のコントローラからPreviousVersions::createVersion()
を呼び出す
<?php
namespace App\Services;
class PreviousVersions extends RequestVariables {
public static function createVersion ($tour) {
dd(parent::$keys_tour);
}
}
:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Services\PreviousVersions;
use App\Tour;
class Tours2Controller extends Controller
{
public static function PreProcess($tour)
{
PreviousVersions::createVersion($tour);
}
}
ことが期待されているものを出力:私ができる
を
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Tour;
use App\Services\PreviousVersions;
class BookingController extends Controller {
public function booking($tour)
{
PreviousVersions::createVersion($tour);
}
}
それは 'ヌル' を出力します
array:2 [
"tour_type" => 0
"city_from" => 1 ]
が、私は別のコントローラで同じ機能を実行するとき同じmを呼び出すときに異なる結果を引き起こすコントローラ間で何が違うのか分かりません民法。誰かが2番目のケースで「null」を出力する理由を教えてもらえますか?
詳細が必要な場合は、お尋ねください。
を? – Camilo
@カミロあなたはもっと具体的になりますか? –
'$ keys_tour'プロパティは、' RequestVariables'クラスの 'init()'メソッドの中で設定されています。 '$ keys_tour'の値を設定するには、そのメソッドを呼び出す必要があります。 – Camilo