Search String

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Wolf_22
Forum Contributor
Posts: 159
Joined: Fri Dec 26, 2008 9:43 pm

Search String

Post by Wolf_22 »

Would searching for the string "&$" work if I'm searching for all call-by-reference actions pertinent to PHP < 5.3?

This may be a stupid move on my part, but due to restrictions on making the development environment identical to the production, I plan on using GREP to replace all "&$" with just "$". That should be a good enough band aid to continue development, right?

What would the cons be in doing this?
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Search String

Post by requinix »

(it's called "call-time pass-by-reference")

That would also catch

Code: Select all

$var=&$othervar;
array($var, &$othervar);
A better match would be

Code: Select all

\b(?!array)(\w+\s*)\(([^)]*?)(^|,)(\s*)&(\s*)\$
to be replaced with

Code: Select all

$1($2$3$4$5\$
Emphasis on "better", as in "not necessarily perfect".


Honestly, I'd rather fix each occurrence as PHP finds it - then there's no risk of accidentally screwing up code.
Wolf_22
Forum Contributor
Posts: 159
Joined: Fri Dec 26, 2008 9:43 pm

Re: Search String

Post by Wolf_22 »

tasairis wrote:(it's called "call-time pass-by-reference")
Ah, I see...
tasairis wrote:Honestly, I'd rather fix each occurrence as PHP finds it - then there's no risk of accidentally screwing up code.
Even if there's thousands to fix? :cry:
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Search String

Post by requinix »

Wolf_22 wrote:
tasairis wrote:Honestly, I'd rather fix each occurrence as PHP finds it - then there's no risk of accidentally screwing up code.
Even if there's thousands to fix? :cry:
Run your search-and-replace, but be prepared to handle other problems that develop.
Post Reply