"Devon H. O'Dell <devon.odell@messagesystems.com>"
Software Engineer - Team Lead; Message Systems, Inc.
@dhobsd, twitter; LinkedIn; probably anywhere else you see dhobsd.
In computer science, a function or expression is said to have a side effect if, in addition to returning a value, it also modifies some state or has an observable interaction with calling functions or the outside world.
1 <?php
2 class Foo {
3 public function process_file($filename) {
4 if (!is_readable($filename)) {
5 return null;
6 }
7
8 $fp = fopen($filename, 'r');
9 if ($fp == false) {
10 return null;
11 }
12
13 /* ... */
14
15 return $processed_file
16 }
1 <?php
2 class Foo {
3 public function camelCase() {}
4 public function under_scored() {}
5 public function reallylongname() {}
6 }
1 <?php
2 class Foo {
3 public function bar($path, $mode, $outdir, $outmode,
4 $flags, $reverse) {}
5 }
PHP itself is in horrific violation of this. Does this look familiar to anyone?
1 <?php
2 class Foo {
3 public function array_search($needle, $haystack) {}
4 public function string_search($haystack, $needle) {}
5 }
1 <?php
2 class Foo {
3 public function sort($array) {
4 if (!is_array($array)) {
5 return false;
6 }
7
8 return usort($array, array('Foo', 'do_sort'));
9 }
10
11 public function min($array) {
12 asort($array);
13
14 if (!is_numeric($array[0])) {
15 return false;
16 }
17
18 return $array[0];
19 }
20 }
Table of Contents | t |
---|---|
Source Files | s |
Slide Numbers | n |
Notes | 2 |
Help | h |