SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2007
    Posts
    69
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    calling method warning (static, non-static..)

    2048 description:Non-static method card::find_cards_by_id() should not be called statically, assuming $this from incompatible context file:.../includes/user.class.php line:12

    it happens by doing this:
    public function cards() {
    return card::find_cards_by_id($this->id);
    }


    The script works, is it ok just ignoring it
    or i should find another way around?

  2. #2
    PHP Guru lampcms.com's Avatar
    Join Date
    Jan 2009
    Posts
    921
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It depends what is in your find_cards_by_id() method.
    if you calling it statically then it cannot have $this variable
    but other than that, it's usually not ok to call non-static method statically. Why not declare it as static?
    My project: Open source Q&A
    (similar to StackOverflow)
    powered by php+MongoDB
    Source on github, collaborators welcome!

  3. #3
    SitePoint Member
    Join Date
    Jul 2006
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You'd really have to post the rest of the code for anyone to see what the problem is.

    You might try just instantiating the object.

    $card = new card();
    return $card->find_cards_by_id($this->id);

  4. #4
    SitePoint Enthusiast
    Join Date
    Apr 2007
    Posts
    69
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, this is a method of 'user' class:
    public function cards() {
    return card::find_cards_by_id($this->id);
    }


    this is the 'card' class:
    function find_cards_by_id($id) {
    $result = self::find_by_sql("SELECT * FROM ".self::$table_name." WHERE user_id = {$id}");
    return $result;
    }

  5. #5
    SitePoint Enthusiast
    Join Date
    Apr 2007
    Posts
    69
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, this is a method of 'user' class:
    public function cards() {
    return card::find_cards_by_id($this->id);
    }


    this is the 'card' class:
    function find_cards_by_id($id) {
    $result = self::find_by_sql("SELECT * FROM ".self::$table_name." WHERE user_id = {$id}");
    return $result;
    }


    I'm sorry, silly me, just now when writing this reply
    i've noticed that find_cards_by_id is not declared as static.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •