Menu

#16 Using method as callback function

open
5
2006-02-07
2006-02-07
Anonymous
No

I created a new zip class ("MYZIP") for some custom zip
functions. This new class extends the PclZip class.
In the new class I stored a custom PCLZIP_CB_PRE_ADD
function which I now wanted to call when creating a zip
archive.

Problem: The statement
"function_exists($v_function_name)" did't find my function.

Solution (starting at line 1685):
// ----- Check that the value is a valid existing function
if(substr($v_function_name,0,7) == "\$this->")
$bolchk = method_exists($this,
str_replace("\$this->","",$v_function_name));
else
$bolchk = function_exists($v_function_name);
if(!$bolchk) {
// ----- Error log

Please note that you have to remove "$this" in the
"method_exists" function, but you need it in the "eval"
function, which follows later.

Now you can use this statement:
$list = $archive->add($filenames,PCLZIP_CB_PRE_ADD,
'$this->myPreAddCallBack');

/Sebastian

Discussion


Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.