tags:

views:

42

answers:

1

Hi,

how do i do a str_replace on everything that is returned in get_defined_vars? doing it with normal strings is easy, but what about objects/classes?

+2  A: 

This sounds like a bad idea, so I'll just answer the actual problem of hardcoded domains. Fix this problem directly instead of applying more bandaid on top of a bad structure.

You should replace every occurrence of a hardcoded domain with a constant (using your text editors search/replace, not PHP), that you can switch however you like.

if (/* something */) {
    define('MYAPP_BASE_URL', 'http://example.com');
} else {
    define('MYAPP_BASE_URL', 'http://example2.com');
}

…

$url = MYAPP_BASE_URL;

Better yet, your code should be dynamic enough to be using $_SERVER['HTTP_HOST'] to begin with.

deceze
yes, i know i should have done this, but i didn't. I hard coded urls (links), etc. I really need to just do a str_replce() on everything in get_defined_vars()
phpno
@phpno That's just a really unrealistic idea. You can only redefine a variable after it has been defined, so you can't just run something on `get_defined_vars` at the top of your script, since no variables will be defined at that point. You'd need to inject this variable changing code between each variable declaration and where it's being used, which is potentially every other line. You'll just have to bite the bullet and de-hardcode your URLs, no other way around it.
deceze