Skip to content

Instantly share code, notes, and snippets.

@mishterk
Created March 7, 2017 04:34
Show Gist options
  • Save mishterk/0fabb95f507565b1a7f71d8c3e3b93e4 to your computer and use it in GitHub Desktop.
Save mishterk/0fabb95f507565b1a7f71d8c3e3b93e4 to your computer and use it in GitHub Desktop.
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