【问题标题】:How can i access a variable that it is inside a static function from another file?如何从另一个文件访问位于静态函数内的变量?
【发布时间】:2019-09-08 16:31:27
【问题描述】:
// * 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";

我希望从另一个文件访问 $recipeImage。

【问题讨论】:

标签: php oop psr-4


【解决方案1】:

无法访问函数内部的变量。

【讨论】:

    猜你喜欢
    • 2014-09-20
    • 2011-01-19
    • 1970-01-01
    • 2014-02-27
    • 2012-09-06
    • 2011-01-14
    • 2010-12-30
    • 2014-12-05
    • 2015-11-17
    相关资源
    最近更新 更多