Skip to main content
PHP Output Prediction Hard +35 XP

Static Property

What does this print?

PHPRead-only
class Counter {
  static $count = 0;
  function __construct() { self::$count++; }
}
new Counter(); new Counter();
echo Counter::$count;

What is the output?

Show answer and explanation

Answer: 2

Static properties belong to the class, not instances. self::$count++ increments the shared counter on each instantiation.

Hint: Static properties are shared across all instances.

What this challenge tests

Output Prediction in PHP: static, oop.

Related challenges