I am looking into source code of the website which was built in the year 2009, it was a custom framework.
What is the difference?
<?php
class DbAccess {
private static $instance;
/**
* Returns the instance of the DB Class
*/
public static function getInstance()
{
self::$instance = new DbAccess();
return self::$instance;
}
}
V/s
<?php
class DbAccess {
/**
* Returns the instance of the DB Class
*/
public static function getInstance()
{
return new DbAccess();
}
}
I have worked on couple of custom-made frameworks and set of libraries with different patterns but, at times, I saw the method of returning instance was via self::$instance
and at times, it was directly returning via new
Which is a good practice? considering upcoming versions of PHP.