Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP awkward function declaration [duplicate]

Tags:

php

Possible Duplicate:
What does it mean to start a PHP function with an ampersand?

Recently I stumbled upon this piece of code:

public static function &get_instance()
{
return self::$instance;
}

What does this kind of function declaration &get_instance() mean? Can the function name be a variable?

like image 778
gopi1410 Avatar asked Jun 18 '26 14:06

gopi1410


1 Answers

It's part of the singleton pattern, in old-style code.

Singleton is a pattern used to make sure that there is only one instance of a class. (Technically it can be used to make sure that there are a certain number of instances of any class, but that number is almost always one.) It's one of the Gang of Four patterns and you can find endless discussion of its use and abuse all over the web.

like image 101
Scott Saunders Avatar answered Jun 21 '26 04:06

Scott Saunders



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!