//class.statictester.php class StaticTester { private static $id = 0; function __construct() { self::$id += 1; } public static function checkIdFromStaticMethod() { echo "Current Id From Static Method is " . self::$id . "<br/>"; } public function checkIdFromNonStaticMethod() { echo "Current Id From Non Static Method is " . self::$id . "<br/>"; } } $st1 = new StaticTester(); StaticTester::checkIdFromStaticMethod(); // output: Current Id From Static Method is 1 $st2 = new StaticTester(); $st1->checkIdFromNonStaticMethod(); // output: Current Id From Non Static Method is 2 $st1->checkIdFromStaticMethod(); // output: Current Id From Static Method is 2 $st2->checkIdFromNonStaticMethod(); // output: Current Id From Non Static Method is 2 $st3 = new StaticTester(); StaticTester::checkIdFromStaticMethod(); // output: Current Id From Static Method is 3 // CONCLUSION: id increases by 1 only when a new instance of StaticTester is instantiated
$newemailerobject->addRecipients('*****@*****.**'); $newemailerobject->setSubject('*****@*****.**'); $newemailerobject->setBody('Hi there :D'); $newemailerobject->sendEmail(); $newemailerobject->sendHtmlEmail(); /*---------- DBDriver ----------*/ $dbdriver = DBManager::getMySQLDriver(); /*---------- Static Tester ----------*/ $tester = new StaticTester(); print "<br>"; StaticTester::checkIdFromStaticMethod(); print "<br>"; $tester2 = new StaticTester(); $tester->checkIdFromNonStaticMethod(); print "<br>"; $tester->checkIdFromStaticMethod(); print "<br>"; $tester2->checkIdFromNonStaticMethod(); print "<br>"; $tester3 = new StaticTester(); StaticTester::checkIdFromStaticMethod(); print "<br>"; /*---------- Student ----------*/ $student = new Student(); $student->name = "Gilmar"; $student->roll = 19; print "{$student->name}<br>"; print "{$student->roll}<br>"; /*---------- Overloader ----------*/ $ol = new Overloader(); $ol->access(2, 3, 4);