Source Code:
(back to article)
<?php // Define a class named MyClass class MyClass { // Declare a public property named myVar public $myVar; // Define the constructor function __construct($value) { // Assign the value passed as an argument to the myVar property $this->myVar = $value; } } // Create a new instance of the class and pass a value to the constructor $obj = new MyClass("some value"); // Output the value of the myVar property echo "Value of myVar: " . $obj->myVar . "\n"; // Output: // Value of myVar: some value ?>
Result:
Report an issue