Shorthand for arrays: is there a literal syntax like {} or []?

Shorthand for arrays: is there a literal syntax like {} or []?

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

Why PHP Lacks a Shorthand for Empty Arrays

In many programming languages, developers enjoy syntactic sugar that reduces boilerplate and improves readability. Consider the double-underscore prefix in C# or the shorthand for empty maps in Kotlin. When asking about array notation in PHP, it is natural to wonder if there exists a literal syntax similar to {} or [] that would allow you to initialize an empty collection with less typing than $list = [];.

The short answer is no. PHP does not currently support a shorthand operator for creating an empty array. Attempting to use curly braces, as shown in the following code snippet, will result in a syntax error:

$list = {}; 
// Parse error: syntax error, unexpected '{', expecting ')'

Even though {} is often associated with objects or associative arrays in other contexts, PHP reserves this syntax strictly for class instantiation (e.g., new ClassName()) and control structures. The language specification does not define an empty array literal using braces. Consequently, the standard and only valid way to declare an empty indexed array remains $list = [];.

Historical Context and Type Safety

The absence of a shorthand like {} is partly rooted in PHP's evolution regarding type handling. In earlier versions of PHP, arrays were loosely typed structures that could hold mixed data types. However, as the language matured, there was a significant push toward type safety to prevent runtime errors.

The introduction of nullable types and union types in modern PHP (8.0+) reinforced the need for explicit syntax. The empty square bracket [] is distinct and unambiguous. It clearly signals an indexed array with no elements. Introducing {} could cause confusion, particularly in contexts where curly braces denote block scopes or object initialization. By enforcing a single, specific syntax for arrays, PHP reduces the cognitive load on developers reading complex codebases.

Practical Alternatives via Type Casting

While you cannot create an empty array with {}, there are scenarios where developers might want to simulate this behavior or convert existing structures. One common pattern involves using type casting to ensure a variable is treated as an array, often necessary when dealing with loosely typed inputs or legacy code.

You can cast a non-array value into an empty array using (array):

$maybeArray = "some string";
$emptyList = (array)$maybeArray; // Results in ['some string']

// To force an empty array specifically:
$strictlyEmpty = (array)''; // Still results in an empty array [], but this is less common than []

However, note that (array) casting on a scalar value like a string or integer will not create an empty array if the variable already holds a value; it merely converts the type. If your goal is strictly to initialize an empty container, [] remains the most direct and efficient approach.

Trade-offs in Language Design

The decision by the PHP core team to omit this shorthand aligns with a broader philosophy of minimizing ambiguity. In languages like JavaScript or Python, {} often represents an object, while [] represents an array. PHP distinguishes these further: {} is reserved for new, and [] is the exclusive syntax for arrays.

If PHP were to introduce {} for empty arrays, it would likely necessitate a major version update to prevent breaking changes in existing parsers and linters. For instance, code relying on {} for block scopes or class instantiation would need re-evaluation. The cost of such a transition outweighs the minor benefit of saving two characters per declaration.

For developers working within the Laravel ecosystem, this consistency is beneficial. Frameworks like LaravelCompany often rely on strict typing and clear data structures to maintain application integrity. Having a predictable syntax for collections ensures that type hints in function signatures remain readable without introducing conflicting symbols.

Ultimately, while $list = []; may seem verbose compared to hypothetical shorthands, it provides the clarity required for robust, maintainable PHP applications.

Our network