Which one of the following can be used to instantiate an object in PHP assuming class name to be Foo?
A.$obj = new $foo;
B.$obj = new foo;
C.$obj = new foo ();
D.obj = new foo ();
Answers
Answered by
2
______✨ HEY MATE ✨______
➡️Option (C) $obj = new foo (); is the right answer ✔️
➡️Option (C) $obj = new foo (); is the right answer ✔️
Answered by
0
$obj = new foo (); can be used to instantiate an object in PHP assuming class name to be Foo. ( Option C is the correct answer)
- The new statement can be used to instantiate a class in PHP to generate a new object.
- PHP objects' blueprints/templates are called classes. Classes do not become objects unless they are instantiated.
- When you instantiate a class, you're creating an instance of it... and thus an object.
- In other terms, instantiation refers to the process of creating a memory instance of an object.
- If you run the PHP code right now, nothing will show up on your website. This is because we haven't told PHP what to do with the object we just created.
Hence, $obj = new foo (); can be used to instantiate an object in PHP assuming class the name to be Foo.
#SPJ2
Similar questions
English,
7 months ago
Math,
7 months ago
Math,
7 months ago
Computer Science,
1 year ago
Computer Science,
1 year ago
Math,
1 year ago
Science,
1 year ago