Php 将查询中的变量存储在类中

Php 将查询中的变量存储在类中,php,class,Php,Class,我有一个images类,我想在该类启动后(登录时)运行查询,然后将profile\u picture\u thumb等变量存储在该类中,或者至少通过this在其他函数中访问它们。以下内容不起作用,并将此字段返回为空 class Images { var $main_prepend = 'm_'; var $thumb_prepend = 't_'; var $default_ext = 'jpg'; var $cropfactor; private $pr

我有一个images类,我想在该类启动后(登录时)运行查询,然后
profile\u picture\u thumb
等变量存储在该类中,或者至少通过
this
在其他函数中访问它们。以下内容不起作用,并将
字段返回为空

class Images
{
    var $main_prepend = 'm_';
    var $thumb_prepend = 't_';
    var $default_ext = 'jpg';
    var $cropfactor;
    private $prepLocation = '';
    private $profile_picture_thumb = '';
    private $profile_picture_large = '';
    private $facebook_id = '';
    public function __construct()
    {
        $sql = Nemesis::select("profile_picture_thumb, profile_picture_large, facebook_id", "users", "id = '{$_SESSION[user_id]}'");
        list($profile_picture_thumb, $profile_picture_large, $facebook_id) = $sql->fetch_row();
        $this->profile_picture_thumb = $profile_picture_thumb;
        $this->profile_picture_large = $profile_picture_large;
        $this->facebook_id = $facebook_id;
        if (local()) {
            $prepLocation = XAMPP;
        } else {
            $prepLocation = '';
        }
    }
    public function profilePic($show = true, $delete = false)
    {
        if ($show) {
            echo '<script type="text/javascript">$(function() { $("#profile-picture").tipsy({fade: true}); });</script>';
            if (is_file(ROOT . $this->profile_picture_thumb)) {
                echo '<img src="' . reduce_double_slashes('../' . $this->profile_picture_thumb) . '" id="profile-picture" class="profile-picture" title="Your Profile Picture">';
            } elseif (!empty($this->facebook_id)) {
                // if there is no profile picture set, and user has listed fb profile picture, get profile picture
                $fb_p_thumb = "http://graph.facebook.com/{$facebook_id}/picture";
                $fb_p_large = "http://graph.facebook.com/{$facebook_id}/picture?type=large";
                echo '<img src="' . $fb_p_thumb . '" id="profile-picture" class="profile-picture" title="Facebook Profile Picture">';
            } else {
                echo '<img src="images/50x50_placeholder.gif" id="profile-picture" class="profile-picture" title="Click to add profile picture">';
            }
        }
        if ($delete) {
            if (is_file(ROOT . $this->profile_picture_thumb) || is_file(ROOT . $this->profile_picture_large)) {
                if (!unlink(ROOT . $this->profile_picture_thumb) && !unlink(ROOT . $this->profile_picture_large)) {
                    $msg->add('e', "Could not delete user profile picture!");
                }
            } else {
                $msg->add('e', "Files not found in directory.");
            }
        }
    }

您确定查询已成功执行并返回结果吗?那么您遇到的具体问题是什么?设置类属性或读取类属性是否有问题?你做了哪些努力来通过调试缩小问题的范围?好吧,那么主要的问题是我在facebook id中缺少了
$this
,这就是我正在查看的内容。让我哑口无言。除此之外,当我尝试调用配置文件中的Images类$Images\u core=newimages时。然后我调用somwhere-else$images_core->profilePic();查询失败,因为出现了一个
致命错误:调用非对象上的成员函数profilePic()
但是,如果我没有在配置中调用新类,这不是问题。并在页面中调用它。无需担心。这是因为我在一个基于过程代码的旧模板中调用它
public function __construct()
{
    static $prepLocation = '';
    static $profile_picture_thumb = '';
    static $profile_picture_large = '';
    static $facebook_id = '';

    $sql = Nemesis::select("profile_picture_thumb, profile_picture_large, facebook_id", "users", "id = '{$_SESSION[user_id]}'");
    list($profile_picture_thumb, $profile_picture_large, $facebook_id) = $sql->fetch_row();
    $this->profile_picture_thumb = $profile_picture_thumb;
    $this->profile_picture_large = $profile_picture_large;
    $this->facebook_id = $facebook_id;
    if (local()) {
        $prepLocation = XAMPP;
    } else {
        $prepLocation = '';
    }
}