a word of warning to others - passing variables by reference

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • lawrence

    a word of warning to others - passing variables by reference

    Those of you with backgrounds with the C language will laugh at my
    mistake, but those of you, like myself, who deal mostly with PHP
    should be warned about passing variables as references - debugging
    then requires a whole new mindset. I've a cms written in procedural
    style that I've been converting to OOP. It is important to always pass
    objects by reference. Unthinkingly, writing the constructors, I also
    passed my config array by reference. This meant that everything that
    happened inside those objects now effected the config array in global
    space.

    Working in PHP you get used to certain things - especially the fact
    that all variables are passed as copies, and that when an array is
    copied it is automatically reset. Having just lost 12 hours trying to
    debug this, I warn you all. If you've got global variables changing
    seemingly without any reason for them to, ask yourself if you've
    passed anything be reference.
Working...