I need to have method to get something from a database, but I don't understand the difference between static and normal functions in PHP.
Example code
class Item { public static function getDetail($arg) { $detail = $this->findProductId($arg); return $detail; } private function findProductId($id) { //find product_id in database where id = $arg //return detail of product } } and function outside of a class
function getDetail($arg) { $detail = findProductId($arg); return $detail; } If I use $item = Item::getDetail(15); and $item = getDetail(15); — they're the same.
- What is the difference between static and function outside of a class?
- If they are difference, How to use static function and function outside of a class? (I'd appreciate a really simple example.)
- What are the performance properties between static and function outside of a class? Which is better?
$item = getDetail(15);would actually fail. Maybe you mean$a = new Item(); $item = $a->getDetail(15)?