Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

caiquecastro's avatar

Const vs Static properties

Hi everyone!

I would like to know whenever you suggest to use class consts or static propeties.

0 likes
4 replies
caiquecastro's avatar

I've already watched this episode but I'm looking for a real case for static properties. Do you know any case where is more appropriate to use static properties instead of consts?

dpde's avatar

Hi,

from my point of view it doesn't really matter and depends on your preferences.

Personally, I like to use constants. For that I create a classes to somehow group them:

class Currency {
    const EUR = 1;
    const CHF = 2;
}
$test = Currency::EUR;
1 like
spekkionu's avatar
Level 47

Constants can only be simple scalar values like strings or integers and the like.

You can have a static property be something more complex like an array.

1 like

Please or to participate in this conversation.