Repeating references

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nathj
    Recognized Expert Contributor
    • May 2007
    • 937

    Repeating references

    Hi,

    Some programming languages have a WITH statement that allows you to do something like this (psuedo code):

    with myobject
    .property1 = variable1
    .property2 = variable2
    .method()
    endwith


    I know that's a bit rough but hopefully you get the idea. Is this possible in PHP? It would prevent me typing $this-> alot.

    Cheers
    nathj
  • kovik
    Recognized Expert Top Contributor
    • Jun 2007
    • 1044

    #2
    Even in languages that have the WITH statement, it is highly advised against. PHP does not support it at all as it's worthless. If you used it, then how would you differentiate between a global function and a class function?

    Comment

    • nathj
      Recognized Expert Contributor
      • May 2007
      • 937

      #3
      Originally posted by volectricity
      Even in languages that have the WITH statement, it is highly advised against. PHP does not support it at all as it's worthless. If you used it, then how would you differentiate between a global function and a class function?
      Okay, in the language I used it in the syntax:
      object.property =1
      object.property 2=2
      object.method()

      would be replaced with

      WITH object
      .property=1
      .property2=2
      .method()
      ENDWITH

      The presence of the '.' indicates that it is a member of the object.

      I was developing in Visual FoxPro and I believe VB has something similar. In my old development language the WITH structure speeds up code as it only checks the object once rather than every time. This is increasingly imortant in visual development for desktop apps when you may be manipulating a class several layers down. You only need to define the path to it once.

      As it si not in PHP I can't use it. I just thought I would double check here on thescripts.

      Cheers
      nathj

      Comment

      Working...