470,609 Members | 1,412 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,609 developers. It's quick & easy.

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

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.
Jul 16 '05 #1
0 2022

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Amr Mostafa | last post: by
3 posts views Thread by domeceo | last post: by
12 posts views Thread by Andrew Bullock | last post: by
27 posts views Thread by Terry | last post: by
5 posts views Thread by Martin Herbert Dietze | last post: by
3 posts views Thread by preitymathur0422 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.