Skip to content

Instantly share code, notes, and snippets.

@mishterk
Created March 7, 2017 04:34
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Simple examples of static class methods and name-spaced functions
<?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');
<?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;
}
}
<?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