PHP new Keyword

P
PHP or Keyword
PHP namespace Keyword

In this article, you will learn how to create a new object in PHP. The new keyword in PHP is used to create an object from a class.

examples of the NEW function

Example 1. In this example, we 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;
?>
PHP or Keyword
PHP namespace Keyword

Add comment

Tutor Network

Share this

Learn PHP from A to Z