Skip to content

Instantly share code, notes, and snippets.

@Vijaysinh
Created August 25, 2021 12:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Vijaysinh/838ceafd9dbdad75197a6d87219e48d6 to your computer and use it in GitHub Desktop.
Save Vijaysinh/838ceafd9dbdad75197a6d87219e48d6 to your computer and use it in GitHub Desktop.
Count How many time class instance got created
<?php
// Count How many time class instance got created
class classA {
public static $counter = 0;
function __construct(){
self::$counter++;
}
}
$obj1 = new classA();
$obj2 = new classA();
echo classA::$counter;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment