PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, May 16, 2022

[FIXED] Why Apache2 (Ubuntu) run defferent with Apache(easyPHP server on Window)?

 May 16, 2022     apache2, easyphp, php, ubuntu     No comments   

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)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing