PHP Class Exercises : Display a string
PHP class: Exercise-1 with Solution
Write a simple PHP class which displays the following string.
'MyClass class has initialized !'
Sample Solution:
PHP Code:
<?php
class MyClass {
public function __construct()
{
echo 'MyClass class has initialized !'."\n";
}
}
$userclass = new MyClass;
?>
Sample Output:
MyClass class has initialized !
Flowchart :

PHP Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: PHP Classes Exercises Home.
Next: Write a simple PHP class which displays an introductory message like "Hello All, I am Scott", where "Scott" is an argument value of the method within the class.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join