-1

How do I set a variable from inside a function? $test is supposed to be an object, I don't know if that makes a difference.

<?php
    $test;

    function hi() {
        $test = new obj();
    }
?>

Whenever I check if $test is set, I get false. This is not a class so I can't do $this->test

bakely
  • 61
  • 14

1 Answers1

2
<?php

function hi() {
    $test = new obj();
    return $test;
}

$test=hi();
?>
RiggsFolly
  • 93,638
  • 21
  • 103
  • 149