w3resource
php Programming Exercies

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 :

Flowchart: Display a string

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?



New Content: Composer: Dependency manager for PHP, R Programming