Jump to content

Recommended Posts

This is one horribly bizare problem:

 

class something {

function __construct() {
	foreach($something as $somethingelse) {
		$this->recurse_merge_unique($array, $array2);
	}
}

private function recurse_merge_unique($fromArray, &$toArray) {
	foreach ($fromArray as $key => $fromValue) {
		if (is_array($fromValue) && isset($toArray[$key])) {
			$this->recurse_merge_unique($fromValue, &$toArray[$key]);
		} elseif (!isset($toArray[$key])) {
			$toArray[$key] = $fromValue;
		}
	}
}

}

 

This extremely cut down sample of my code works no problem like this, but the really screwed up fact is that is ALSO works like this:

 

class something {

function __construct() {
	foreach($something as $somethingelse) {
		$this->recurse_merge_unique($array, $array2);
	}
}

private function recurse_merge_unique($fromArray, &$toArray) {

}

}

 

Empty function! And it works like a charm. I took ALL variables out of the sleep function so nothing is saved, that function isn't found anywhere in my entire application, and I've wiped the site's cookies numerous times so the object isn't getting saved, and yet it still works as if it weren't empty. If I uncomment the mystery function from the contruct function, then it doesn't act of course, but it works like a charm when called despite the fact there being NO CODE in it. Naturally, this has boggled my mind. Any ideas? I've left the recurse function exactly as it is in my script.

Link to comment
https://forums.phpfreaks.com/topic/138500-empty-function-still-does-its-job-huh/
Share on other sites

Nope, it doesn't echo anything, so I guess it's not being called. When it's commented out in the construct function, then the arrays are not merged, if it's not commented out and the function is empty, the arrays are merged. Also, when I take out the recurse function all together, I get a "call to undefined method".

 

My guess is that I have a phantom recurse_merge_unique() function defined somewhere in limbo, as it's in only one place in my entire application.

Ok that I know, but this function DOES do something. The empty function recursively merges the arrays even with no code.

The only instance I've seen of phantom code was with APC enabled, and apc.stat = 0

You're not using any bytecode cacheing are you?

The only instance I've seen of phantom code was with APC enabled, and apc.stat = 0

You're not using any bytecode cacheing are you?

 

APC is enabled with apc.stat = 1, though I have no idea what APC is. As for bytecode cacheing, I really don't know. I've built my server from scratch and I've never looked into bytecode cacheing, so unless it's enabled by default, I don't think it's on.

Update...

 

The phantom code still runs even though the function is empty, regardless of the variable names in the () part of the function, although taking out the reference character breaks it's functionality! So:

 

private function recurse_merge_unique($fromArray, &$toArray) {

}

 

...will merge the arrays, and so will:

 

private function recurse_merge_unique($blueberry_jam, &$banana_rum) {

}

 

But not:

 

private function recurse_merge_unique($fromArray, $toArray) {

}

 

And one last thing, even if I rename the function, it STILL works without the code.

 

How's that for confusing? This makes no sense at all.

Ok, something is just horribly wrong here, things are not acting right. I renamed our little function once, no difference, a second time, and I got this:

 

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /var/www/sandbox.[website].com/classes.php:1) in /var/www/sandbox.[website].com/index.php on line 35

Fatal error: main() [<a href='function.main'>function.main</a>]: The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "user" of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide a __autoload() function to load the class definition in /var/www/sandbox.[website].com/index.php on line 74

 

I use output buffering so I should not get the headers already sent error, but I figure I screwed up somewhere with the serialization of my objects, so I re-did the serialization code as follows:

 

	function startObjects($array) {

	foreach ((array) $array as $class) {
		$object = substr($class, 0, 1);
		$_SESSION[$object] = isset($_SESSION[$object]) ? $_SESSION[$object] : new $class;
		$GLOBALS[$object] =& $_SESSION[$object];
	}

}

startObjects(array('messages', 'user', 'processor', 'snippets'));

 

Yes, I like to use the first letter of the class as my object name, I'm just different that way. Anyways, I get this error:

 

<br />
<b>Warning</b>:  session_start() [<a href='function.session-start'>function.session-start</a>]: Cannot send session cookie - headers already sent by (output started at /var/www/sandbox.[website].com/classes.php:1) in <b>/var/www/sandbox.[website].com/index.php</b> on line <b>35</b><br />
<br />
<b>Warning</b>:  session_start() [<a href='function.session-start'>function.session-start</a>]: Cannot send session cache limiter - headers already sent (output started at /var/www/sandbox.[website].com/classes.php:1) in <b>/var/www/sandbox.[website].com/index.php</b> on line <b>35</b><br />

<br />
<b>Fatal error</b>:  Class 'messages' not found in <b>/var/www/sandbox.[website].com/functions.php</b> on line <b>68</b><br />

 

Removed cookies, no more error. I figure it was trying to unserialize an object using a class that has different properties/methods that the object was originally created with.

 

So I run my recurse function, and the arrays merge without the code. Renamed the function again, same thing as above, renamed the class and object, SAME THING. I've SSHed into my server and checked the code first hand to make sure my desktop computer wasn't caching anything, and sure enough all the re-named junk is there.

 

What on earth is going on???

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.