Issue
I have a draft class:(Update)
class abb{
   static $fieldSelect;
   function init() {
        self::$field = require_once('inputs/Mapping.php');
   }
   function getField($item) {
        return self::$fieldSelect[$item];
   }
}
and Mapping.php contain:
<?php
return array(
    ItemType::Food          => 0.7,
    ItemType::Fashion       => 0.5,
);
It runs well on easyPHP(windows 7), but when I deploy it onto Apache2(Unbutu), an error exception appears. For example, I input $item = "Phone" (Update here), Apache2 throws exception:Undefined index: Phone at line return self::$fieldSelect[$item]; If $fieldSelect[$item] does not exist, sever on Window will be return NULL but Ubuntu is not. I just wana see the different between Window and Ubuntu when run it.
I don't understand why it is so?
Solution
I don't see $fieldSelect declared anywhere in your class. Perhaps you should be using $field instead?
You are also using $fields and $field.
Perhaps this will do:
class abb{ 
   static $fields; 
   function init() { 
        self::$fields = require_once('inputs/Mapping.php'); 
   } 
   function getField($item) { 
        return self::$fields[$item]; 
   } 
} 
Finally, you will need to address the array key properly. I am not sure what your ItemType is defined as. Maybe using $item = ItemType::Food to access the key would help.
Answered By - F21 Answer Checked By - Candace Johnson (PHPFixing Volunteer)
 
 Posts
Posts
 
 
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.