foreach()
ループに入る前に定義されたいくつかの変数を取得する静的関数があります。
の中から、変数foreach()
を呼び出して$pnUuid
、取得 しようとしました
未処理の例外 未定義の変数: pnUuid
ループの前にvar を正常にエコーできます。また、その print の直後にorを付ければ、ループ内からも正常にエコーできます。
呼び出しも例外を回避しますが、var はNULLです:(die()
continue
global $pnUuid
public static function find( $input )
{
// instantiate
$resultsByBrand = array();
$brandDictionary = new BrandHashTable();
// attempt to get a PN UUID
$partnumber = PartNumberEntity::where( 'number', '=', $input['partnumber'] )->first();
$pnUuid = empty($partnumber) ? false : $partnumber->uuid;
// get current inventory for the PN
$rzStocklines = RzStockEntity::where('fullpartnumber', '=', $input['partnumber'])
->get( array('fullpartnumber', 'manufacturer', 'quantity'));
// process the stocklines
foreach( $rzStocklines AS $row )
{
// do our darndest to get a UUID for the Brand
$brandDictionary->registerByName($row->manufacturer);
$brandUuid = $brandDictionary->getUuid($row->manufacturer);
// set a key of either the brand name, or the uuid
$key = $brandUuid ? $brandUuid : $row->manufacturer;
// instantiate the object for this brands results
if( !array_key_exists($key, $resultsByBrand))
{
$resultsByBrand[$key] = new stdClass();
$resultsByBrand[$key]->partnumber = $row->fullpartnumber;
$resultsByBrand[$key]->brand = $row->manufacturer;
$resultsByBrand[$key]->quantity = 0;
$resultsByBrand[$key]->minimum_order_quantity = 1;
}
// include the qty with the total sum
$resultsByBrand[$key]->quantity += $row->quantity;
// make sure we need Product-level info before doing the work to get it
if( !isset( $resultsByBrand[$key]->grams_piece_weight ))
{
//echo '<pre>Brand UUID:<br />',print_r($brandUuid, TRUE),'</pre>'; // For Testing ----->
//echo '<pre>PN UUID:<br />',print_r($pnUuid, TRUE),'</pre>'; // For Testing ----->
//die('(Dead by request)'); // For Testing ----->
/**
* This is a _**wierd**_ one ...
* An "Undefined Variable: $pnUuid" exception is getting thrown.
* If we call "die()" or "continue()", it goes away.
* Casting it as a global also works, but then it is NULL
*/
global $pnUuid; // hackity hack hack hack
// check for product-level info
if( $brandUuid && $pnUuid )
{
$product = ProductEntity::where(
function ($query) use ($brandUuid, $pnUuid) {
$query->where('partnumber_uuid', '=', $pnUuid);
$query->where('company_uuid_brand', '=', $brandUuid);
})
->first();
// add product-level info to $resultsByBrand[$key]
if( !empty( $product ))
$resultsByBrand[$key]->grams_piece_weight = $product->piece_weight;
} //if( $brandUuid && $pnUuid...
} //if( !property_exists...
unset( $brandUuid, $pnUuid );
} //foreach( $rzStocklines AS...
return $resultsByBrand;
}
ここで一体何が起こっているのですか?
ところで、私も非静的メソッドとして試してみましたが、それでも同じ例外がスローされます。