Skip to content

Instantly share code, notes, and snippets.

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
You can’t perform that action at this time.