Announcement

Collapse
No announcement yet.

The -> thingy

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • The -> thingy

    What is this "function" and how does it work? I have seen it profusely in VBB but I havent a real clue as to how it works. I assume that it sets the database and then performs the entered function in that database, but thats all i can deduce really. From what i see, if nothing else, it centralizes everything and cleans up the code a lot. Thanks for any help
    Heres an example i found in a VBB script:
    PHP Code:
    $DB_site->free_result($forumsperms); 

  • #2
    yeah

    "The -> thingy" as you so put it, has nothing to do with what you were talking about.

    It is the same as a . in a class in C++.

    For example, say there is a class called database and it is constructed like so:

    class database {
    function free_result($result) {
    mysql_free_result($result);
    }
    };

    That class is then called like so:

    $DB_site = new database;
    $DB_site->free_result($forumsperms);

    So the -> operator calls a member, a function in this case, of the class database.

    Hope this helps.

    -Vic

    Comment


    • #3
      um, hmm.
      ok, so what i could do is set a group of functions inside a class like this:

      class happy {

        function smiley($1) {
            // do function stuff
            $out = "$1" . " is the output";
            return($out);
        }

      };

      and then do this to set the class i want.....

      $class = happy;

      and then call that function by doing this....

      $class->smiley("foo");

      right? so what if i want to get the output in a variable? i doubt that doing

      $variable = $class->smiley("foo");

      would give me

      "foo is the output"

      like the function is supposed to do

      and is there a way to have that class call perform all the functions in the class? or do i have to program all my functions into a 'parent' function inside that class?

      am i doing this right?

      Comment


      • #4
        another example thats confusing me:

        PHP Code:
        // init db **********************
        // load db class
        $dbclassname="./admin/db_$dbservertype.php";
        require(
        $dbclassname);

        $DB_site=new DB_Sql_vb;

        $DB_site->appname='vBulletin';
        $DB_site->appshortname='vBulletin (forum)';
        $DB_site->database=$dbname;
        $DB_site->server=$servername;
        $DB_site->user=$dbusername;
        $DB_site->password=$dbpassword;

        $DB_site->connect();
        // end init db 

        Comment


        • #5
          It's all really quite simple.

          $DB_site=new DB_Sql_vb;
          The above creates a new INSTANCE of the class DB_Sql_vb, assigning it to $DB_site

          Then use functions defined in the DB_Sql_vb class:
          $DB_site->function();

          You can also set variables within the class:
          $DB_site->appname='vBulletin';

          So the above is setting the variable $appname within the DB_Sql_vb class to 'vBulletin'

          Comment


          • #6
            and when i call a class all the variables are relative to it?
            and how do i take output from it then?

            Comment


            • #7
              Just the way you access variables & functions that are NOT in classes, only you prefix them with the object variable

              so instead of
              $variable

              you'd use
              $DB->variable

              instead of
              function()

              you'd use
              $DB->function()

              so if we have this function

              function domath($number1,$number2) {
              $newnumber = $number1 + $number2;
              return $newnumber;
              }

              And that function is located with the class called Math

              so we create a new instance of the class

              $math = new Math;
              $hoursinyear = $math->domath(365,24);

              There you have it, play around a little and visit hotscripts.com to find some good tutorials.

              Comment


              • #8
                hey sweet, im getting this
                thanks a lot
                i think i found a tutorial on zend for it too

                Comment

                widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
                Working...
                X