Using Function as argument to constructor

From: Date: Tue, 25 Jul 2000 21:03:01 +0000
Subject: Using Function as argument to constructor
Groups: php.general 
Request: Send a blank email to php-general+get-8138@lists.php.net to get a copy of this message
I get the following error when trying to pass in a function as an argument, could someone help me, please? And if you see any other errors, like how to test if a variable passed in is 'set' and whether that works or not, I'd appreciate that too. TIA [{:-)>~ ------------ Parse error: parse error, expecting T_OLD_FUNCTION' or T_FUNCTION' or T_VAR' or '}'' in SafeTypedSTR.php on line 3 ------------ I tired passing in the function as: TestURL, $TestURL, TestURL(), $TestURL(), and none worked. ------------ The Code is as follows, both are in my <public_html> directory, it's on a machine with the latest and greatest PHP4 -----------<index.php>----------- <?php require ('SafeTypedSTR.php'); ?> <!doctype html public "-//w3c//dtd html 4.0 transitional//en"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <meta name="Author" content="Dennis Gearon"> <meta name="GENERATOR" content="Mozilla/4.61 [en] (Win95; U) [Netscape]"> <title>index</title> </head> <body> <?php $function TestURL($URL){ return preg_match("/^http\:\/\/[\w\-_\.]+\/[\w\%_\-\.\/]*$/i",$URL); } $mine = new SafeTypedSTR($TestURL); ?> </body> </html> -----------<SafeTypedSTR.php>----------- <?php class SafeTypedSTR{ SafeTypedSTR($ExtTypingFunc){ if(isset($ExternalTypingFunc) this->TypingFunc=$ExternalTypingFunc; else unset(this->$TypingFunc); } var $STR; var $TypingFunc; PutSafeTyped($arg){ if(!isset(this->$TypingFunc)); else if(!isset($arg)); else if (TypingFunct($arg)){ this->$STR=$arg; return 1; } unset(this->$STR); return 0; } GetSafeTyped(){ if(this->Validate()) return this->$STR;} Validate(){ if(!isset(this->$TypingFunc)); else if(!isset(this->$STR)); else if (TypingFunct(this->$STR)) return 1; unset(this->$STR); return 0; } } ?> -- ________________________________________________________________ Dennis K. Gearon (Kegley) Scientific Instrument Technician, School of EIT Oregon Institute of Technology - One of USA's 100 Best College Buys 3201 Campus Drive Klamath Falls, OR 97601 Voice 1-541-885-1563 FAX 1-541-885-1689 email gearond@oit.edu ________________________________________________________________ Happiness is when you want to go to your job in the morning and when you want to go home in the evening. ________________________________________________________________

« previous php.general (#8138) next »