JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
added stupid hack so I can have a default for a "pass by reference" parameter
[wfpl.git] / misc.php
1 <?php
2
3 function read_whole_file($name) {
4         $fd = fopen($name, 'r');
5         if($fd === false) {
6                 die("Failed to read file: '$name'");
7         }
8         $file_data = fread($fd, filesize($name));
9         fclose($fd);
10         return $file_data;
11 }
12
13 function unix_newlines($str) {
14         $str = str_replace("\r\n", "\n", $str);
15         return str_replace("\r", "\n", $str);
16 }
17
18 # return current year (all 4 digits)
19 function this_year() {
20         return strftime('%Y');
21 }
22
23 # return the number of the current month (1..12)
24 function this_month() {
25         return strftime('%m');
26 }
27
28
29 # php4 is broken, in that you cannot set a default value for a parameter that
30 # is passed by reference. So, this is set up to use the following screwy
31 # syntax:
32 #
33 # function foo($bar = 0) {
34 #   if($bar !== 0) {
35 #     $bar = $bar->ref;
36 #   }
37 #       ...
38 # }
39 #
40 # foo();
41 # foo(ref($baz));
42
43 class stupid_reference {
44         var $ref;
45         function stupid_reference(&$ref) {
46                 $this->ref = &$ref;
47         }
48 }
49 function ref(&$foo) {
50         return new stupid_reference($foo);
51 }
52
53 ?>