Created
March 7, 2017 04:34
-
-
Save mishterk/0fabb95f507565b1a7f71d8c3e3b93e4 to your computer and use it in GitHub Desktop.
Simple examples of static class methods and name-spaced functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
include 'utility-class.php'; | |
include 'utility-functions.php'; | |
// using a static class method | |
$processed = UtilityClass::methodOne( 'some data' ); | |
// using a namespaced function | |
$processed = \MyUtilityFunctions\functionOne('some data'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class UtilityClass { | |
/** | |
* Accepts a value and does … with it. | |
* | |
* @param $data | |
* @return mixed | |
*/ | |
static function methodOne( $data ) | |
{ | |
// ... do stuff ... | |
return $data; | |
} | |
/** | |
* Accepts a value and does … with it | |
* | |
* @param $data | |
* @return mixed | |
*/ | |
static function methodTwo( $data ) | |
{ | |
// ... do stuff ... | |
return $data; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace MyUtilityFunctions { | |
/** | |
* Accepts a value and does … with it | |
* | |
* @param $data | |
* @return mixed | |
*/ | |
function functionOne( $data ) | |
{ | |
// ... do stuff ... | |
return $data; | |
} | |
/** | |
* Accepts a value and does … with it | |
* | |
* @param $data | |
* @return mixed | |
*/ | |
function functionTwo( $data ) | |
{ | |
// ... do stuff ... | |
return $data; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment