Announcement

Collapse
No announcement yet.

What does "->" do?

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

  • What does "->" do?

    I've noticed that in PHP some people use -> instead of =

    For example:
    $DB_site->query("INSERT INTO thread (threadid,title,lastpost,forumid,open,replycount,postusername,lastposter,dateline,iconid,v iews,notes ,visible) VALUES (NULL,'".addslashes($threadtitle)."',$threaddate,$destforumid,$open,$replycount,'".addslas hes($postusername)."','',$threaddate,$iconid,0,'',1)");

    What does -> do?


  • #2
    -> is the symbol for a "pointer".

    In your reference above "query" is a member of the class $DB_site and so to reference it one uses the "->" operator.

    Comment


    • #3
      You'll notice this also in Object Oriented Perl Scripts ( OOP ) . This way of programming ( OOP ) is very efficient and more reliable because everything is done through an 'Object'.

      Comment


      • #4
        Actually, I wouldn't really recommend coding in OOP in PHP too much. PHP wasn't really designed for it, and judging by a little bit of their implementation, it seems like it's an afterthought. (...and references too)

        Comment


        • #5
          My entire PHP knowlege consists of the include function, so I can't really comment on the in's and out's of ref'fing / def'fing and OO php.

          But, with perl - OO programming is an excellent way to speed up repitive tasks and to increase the flow speed, to me it makes far more logical sense build a lexically scoped hash table that's blessed to a class.

          Referencing variables works really well in perl too. Once the hash table (or array list, etc) is loaded into memory, referencing it when passing it around increases performance as perl doesn't have to rebuild the table everytime you call it.

          That's why the grand'pa of all databases, the Berkeley Database was (and is still) popular.

          Comment


          • #6
            Yes, you are right Mike, PHP was not designed to be Object Oriented programming language.

            Comment


            • #7
              It is damn good for wrappers, but you could actually fake that with variable function names (somewhat):

              PHP Code:
              function variable($text) {
              echo 
              $text;
              }

              $var 'variable';

              $var('This is the text that I wish to print'); 
              So you could fake a wrapper by changing the variable $var to equal 'othervariable' and run the othervariable function.

              Comment

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