Syntax
class Counter {
public static int $total = 0;
}Examples
PHP static members example
A focused example you can adapt while practising.
class Counter {
public static int $total = 0;
}Best practices
- Start with the smallest working example, then adapt it to your project.
- Use the language’s standard library and idioms before introducing extra dependencies.
At a glance
- Purpose
- Server-side web applications
- File extension
- .php
- Runs in
- PHP runtime on a server or CLI
- Usually used with
- HTML, databases and web servers
Specifications & further reading
Related PHP documentation
PHP Classes & Interfaces
Classes define objects, while interfaces define methods an implementing class must provide. Visibility controls whether members are public, protected, or private.PHP namespaces
PHP reference for php namespaces.PHP use imports
PHP reference for php use imports.PHP class definitions
PHP reference for php class definitions.
Classes define objects, while interfaces define methods an implementing class must provide. Visibility controls whether members are public, protected, or private.PHP namespaces
PHP reference for php namespaces.PHP use imports
PHP reference for php use imports.PHP class definitions
PHP reference for php class definitions.