---
title: "lint/refactor/prefer-constant"
pagination: false
---

{/* Generated by scripts/gen-rule-docs.py. Edit mapping.toml, not this file. */}

<RuleId id="lint/refactor/prefer-constant" />

In the [`coding-style`](/docs/rules/sets/coding-style) set. Unsafe fix: it can change behaviour.

## What it does

Replace function calls that return a constant (php_sapi_name(), pi(), ...) with the constant.

## Configuration

```toml title="pun.toml"
[lint.rules]
"refactor/prefer-constant" = "error"
```

To skip it in some files, add an [override](/docs/configuration/pun-toml#lint) or a [`@pun-ignore-file`](/docs/configuration/ignore-comments) comment.

## Options

| Name | Type | Allowed values | Default | Upstream name |
| --- | --- | --- | --- | --- |
| `functions` | `list` | `get-called-class`, `get-class`, `get-class-this`, `php-sapi-name`, `phpversion`, `pi` | `["get-called-class", "get-class", "get-class-this", "php-sapi-name", "phpversion", "pi"]` | `functions` |

## Replaces

- [`function_to_constant`](https://cs.symfony.com/doc/rules/language_construct/function_to_constant.html) (php-cs-fixer, risky)

[More lint/refactor rules](/docs/rules/lint/refactor) · [Edit this page](https://github.com/shipfastlabs/pun/edit/main/crates/pun-config/rules/mapping.toml)
