0
// * SELECTING ALL POSTS.
    public static function selectAllPosts() {

        $query = Database::Connect()->prepare("SELECT * FROM posts");
        $query->execute();
        $recipe = $query->fetch(\PDO::FETCH_OBJ);

        // THIS IS THE TARGET.
        $recipeImage = $recipe->recipe_image;

        return true;
    }

    // THIS IS ANOTHER PHP FILE.
    $recipe_image = Posts::selectAllPosts()->$recipeImage ?? "default-recipe- 
    picture.png";

i expect $recipeImage to be accessed from another file.

Masivuye Cokile
  • 4,754
  • 3
  • 19
  • 34
SaiKen
  • 1
  • 1
  • 3
    Possible duplicate of [Reference: What is variable scope, which variables are accessible from where and what are "undefined variable" errors?](https://stackoverflow.com/questions/16959576/reference-what-is-variable-scope-which-variables-are-accessible-from-where-and) – Masivuye Cokile Apr 18 '19 at 10:41
  • 1
    Possible duplicate of [Access a static variable by $var::$reference](https://stackoverflow.com/questions/675676/access-a-static-variable-by-varreference) – Soutzikevich Apr 18 '19 at 11:52

1 Answers1

0

It's not possible to access variables inside function.

Andrei Lupuleasa
  • 2,677
  • 3
  • 14
  • 32