PHP new Keyword
Example
Create an object and output the value of one of its properties:
<?php
class MyClass {
public $name = "John";
}
$obj = new
MyClass();
echo "The name is " . $obj->name;
?>
Try it Yourself »
Definition and Usage
The new
keyword is used to create an object from a class.
Related Pages
Learn more about classes and objects in our PHP OOP - Classes and Objects Tutorial.
❮ PHP Keywords