View Single Post
  #1  
Old 07-06-2008, 10:37 PM
DrakilorP2P DrakilorP2P is offline
Registered User
DrakilorP2P's Avatar
Join Date: Apr 2006
Posts: 755
DrakilorP2P is just really niceDrakilorP2P is just really nice
Object method declaration in joined classes.

I think this is the correct forum this time.
Following is a description of what I assume is a bug. I managed to rule out any human factor.

My stuff behaved like it was magic for a while until I succeeded in isolating the problem.

It seems like functions in a joined class isn't fully aware of what is happening in the real script. The following scripts creates two TStaticVars and assigns anonymous functions to them, one in a joined class-function and one native. The functions both end up with the same identifier, function_1, and whichever function was defined first is overwritten.

A DBNPC:
PHP Code:
function onCreated()
{
  
join("some_class");
  
temp.foo createNewTStaticVarFromAnotherClass();
  
  
temp.foo.forkFunctionCollision();
  echo(
temp.foo.forkFunctionCollision);
  
  
temp.bar = new TStaticVar();
  
temp.bar.secondFunctionCollision = function() {
    echo(
"secondFunctionCollision");
  };
  
  
temp.bar.secondFunctionCollision();
  echo(
temp.bar.secondFunctionCollision);

some_class:
PHP Code:
function createNewTStaticVarFromAnotherClass()
{
  
temp.crux = new TStaticVar();
  
temp.crux.forkFunctionCollision = function() {
    echo(
"forkFunctionCollision");
  };
  
  return 
temp.crux;

Output:
Quote:
secondFunctionCollision
function_1
secondFunctionCollision
function_1
I assume this is supposed to output:
Quote:
forkFunctionCollision
function_1
secondFunctionCollision
function_2

Oh, hello mister inappropriate censorship; I think I'll rename firstFunctionCollision() to something else.
That's word censor evasion 101 by the way.

Last edited by DrakilorP2P; 07-07-2008 at 04:24 PM.. Reason: Improved sentence structure.
Reply With Quote