Question

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?

Was it helpful?

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.

OTHER TIPS

I'd assume that the error reporting level was configured differently on the different systems.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top