PHP new Keyword

❮ PHP Keywords

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
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.