1

How do I make the variable item from one PHP file visible to a PHP class that is a different file?

The variable:

$item = "item";

The class:

class Item{
  public function getItem(){
     $result = $item + 5;
     echo $result;
  }
}
  • Put `global $item;` in the function. It doesn't matter if they're in the same or different files. – Barmar Feb 24 '22 at 19:20

0 Answers0