No announcement yet.

The -> thingy

  • 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:

  • #2

    "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) {

    That class is then called like so:

    $DB_site = new database;

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

    Hope this helps.



    • #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";


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

      $class = happy;

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


      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?


      • #4
        another example thats confusing me:

        PHP Code:
        // init db **********************
        // load db class

        $DB_site=new DB_Sql_vb;

        $DB_site->appshortname='vBulletin (forum)';

        // end init db 


        • #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:

          You can also set variables within the class:

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


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


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

              so instead of

              you'd use

              instead of

              you'd use

              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 to find some good tutorials.


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


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