Not signed in (Sign In)

SkillShare - A place to discuss Web Standards and Web Design topics

Categories

Vanilla 1.1.9 is a product of Lussumo. More Information: Documentation, Community Support.

  1.  permalink
    Im not exactly sure why Im getting an error. I feel as though I have done this a million times before without a hitch. First off this is running on a php5 server for reference.

    im getting this error
    call to a member function string_tool() on a non-object in '<some file>' on line 85

    that line is
    if($core->string_tool($_SESSION['user_id'],'ip')) return(1);

    now i know just having the line doesn't help at all without some background so here is a summary of the files.

    file1.php
    class core {
    function __construct() {
    if(!include_once('file2.php')) echo "failed to load 'file2.php', must be a brain fart";
    }

    public function string_tool(<some vars>) {
    echo 'woot';
    }
    }

    $core = new core;


    file2.php
    class users {
    function __construct() {
    if(!include_once('file2.php')) echo "failed to load 'file2.php', must be a brain fart";
    }

    public function check_login() {
    global $core;
    if($core->string_tool($_SESSION['user_id'],'ip')) return(1); // this is line 85
    }
    }

    $users = new users;


    If any more information is required just ask. ANY help would be great.

    The part in the error 'on a non-object' leaves me to believe that it may not be with my overall scheme but i dont why i would be unable to call that function.

    i also attempted to echo some variables in core without success
  2.  permalink
    OK.. wow ok so after about another hour of testing and playing with it i figured it out.

    If you have a class that includes other classes from other files those two classes cant talk to each other. i didnt test to see if they could extend. that might solve my problem better but i figured out that if you include those files at teh global level and not inside a class like you should everything works fine.
    •  
      CommentAuthorjernigani
    • CommentTimeOct 29th 2007 edited
     permalink
    There is a way to extend classes in php.

    Just use the word extend between a new object and your old object. Then you will be able to use $this-> instead of $core->

    class newClass extends mainClass{
    now you can use all of the objects from the mainClass in your newClass
    }


    So for your example I think it should be,


    class users extends core{
    public function check_login() {
    if($this->string_tool($_SESSION['user_id'],'ip')) return(1);
    }


    I hope this helps!
  3.  permalink
    Thanks, i have played very little with PHP 5 extend and would like to do so. i will try and see if this will work for what im doing.
Add your comments
    Username Password
  • Format comments as (Help)