- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Can we define constant in class constructor PHP?
No, you cannot define constant in class constructor, you can use constant at the class level.
Let’s say we have the following class −
class ConstantDemo { }
Define a constant in the class −
class ConstantDemo { const LANGUAGE_NAME="PHP"; }
Example
<!DOCTYPE html> <html> <body> <?php class ConstantDemo { const LANGUAGE_NAME="PHP"; } echo "The language Name is=",ConstantDemo::LANGUAGE_NAME; ?> </body> </html>
Output
The language Name is=PHP
- Related Articles
- Can we define a parameterized constructor in an abstract class in Java?
- Can we define a static constructor in Java?
- Can we define constructor inside an interface in java?
- Can we define an enum inside a class in Java?
- Can we define a class inside a Java interface?
- Can we define an interface inside a Java class?
- Can we define an abstract class without abstract method in java?
- How can we call one constructor from another in the same class in C#?
- How to call parent constructor in child class in PHP?
- Can we define an abstract class with no abstract methods in Java?
- Can we define a method name same as class name in Java?
- Can we define multiple methods in a class with the same name in Java?
- Can we declare constructor as final in java?
- Can we have a constructor private in java?
- Can we declare a constructor as private in Java?

Advertisements