Results 1 to 8 of 8

Thread: What Does This Code Do? [Resolved, Comments Welcome]

Threaded View

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2002
    Location
    Durham, NC, US
    Posts
    218

    What Does This Code Do? [Resolved, Comments Welcome]

    Code:
    function compare($var1,$var2)
    {
    	$string = "if($var1 $var2)
    	{
    		\$res=1;
    	}
    	else
    	{
    		\$res=0;
    	}";
    
    	eval("$string;");
    	return $res;
    }
    I'm trying to make sense of this code in this busted PHP application at work. Just to give you an idea, this function is usually called compare("foo", "==bar") . The quotes around the if blocks, the lack of a logic operator, the dereferencing of $res, the random eval(), I don't get it.
    Last edited by Travis G; Sep 24th, 2004 at 10:39 AM.
    Travis, Kung Foo Journeyman

    Web Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.5 Guide and Reference
    Perl: Documentation, Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
    OSS: Mozilla, MySQL (Manual)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width