- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
Advertisements