Constants In PHP Object Oriented Programming

Today I will talk about constants which are very useful in development. Before we dive into code samples, there are a few things you have to remember.

  1. – It is declared inside a class with the const keyword.
  2. – They are case-sensitive. It’s better to name them all upper case letter for best practice.
  3. – We can access them back outside of the class with this operator (::)

Let’s see a simple constant and it has been called outside of the class.

And also we can access the constant within the class like this using self keyword.

By Yuuma



アプリ関連ニュース

お問い合わせはこちら

お問い合わせ・ご相談はお電話、またはお問い合わせフォームよりお受け付けいたしております。

tel. 06-6454-8833(平日 10:00~17:00)

お問い合わせフォーム