JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
added stupid hack so I can have a default for a "pass by reference" parameter
authorJason Woofenden <jason183@herkamire.com>
Thu, 28 Dec 2006 09:51:23 +0000 (04:51 -0500)
committerJason Woofenden <jason183@herkamire.com>
Thu, 28 Dec 2006 09:51:23 +0000 (04:51 -0500)
calendar.php
misc.php

index 78fc206..d9a7d29 100644 (file)
@@ -49,9 +49,16 @@ function calendar_day($kind, &$template) {
        $template->sub('day');
 }
 
-function calendar($year, $month, $events = 0, &$template = 0) {
-       if($template == 0) {
-               $template = $GLOBALS['wfpl_template'];
+# php4 is broken, in that you cannot set a default value for a parameter that
+# is passed by reference. So, this is set up to use the following screwy
+# syntax:
+#
+# calendar('2006', '12', $events, ref($my_template))
+function calendar($year, $month, $events = 0, $template = 0) {
+       if($template === 0) {
+               $template = &$GLOBALS['wfpl_template'];
+       } else {
+               $template = &$template->ref;
        }
 
        if(strlen($year) == 2) {
index 4e1da44..abe5c28 100644 (file)
--- a/misc.php
+++ b/misc.php
@@ -25,4 +25,29 @@ function this_month() {
        return strftime('%m');
 }
 
+
+# php4 is broken, in that you cannot set a default value for a parameter that
+# is passed by reference. So, this is set up to use the following screwy
+# syntax:
+#
+# function foo($bar = 0) {
+#   if($bar !== 0) {
+#     $bar = $bar->ref;
+#   }
+#      ...
+# }
+#
+# foo();
+# foo(ref($baz));
+
+class stupid_reference {
+       var $ref;
+       function stupid_reference(&$ref) {
+               $this->ref = &$ref;
+       }
+}
+function ref(&$foo) {
+       return new stupid_reference($foo);
+}
+
 ?>