--- swig-1.3.30/Source/Modules/php.cxx.orig 2006-11-02 00:54:52.000000000 +0100 +++ swig-1.3.30/Source/Modules/php.cxx 2006-11-18 20:49:44.639530500 +0100 @@ -1172,6 +1172,8 @@ /* Insert cleanup code */ for (i = 0, p = l; p; i++) { + if(i>= (num_required)) + Printf(cleanup,"\tif(arg_count > %d) {\n", i); if ((tm = Getattr(p, "tmap:freearg"))) { Replaceall(tm, "$source", Getattr(p, "lname")); Printv(cleanup, tm, "\n", NIL); @@ -1179,6 +1181,8 @@ } else { p = nextSibling(p); } + if (i >= num_required) + Printf(cleanup,"}\n"); } /* Insert argument output code */