DrSchool Learn coding, fast.
EN AR BN CS DE EL Search

Classes / Objects — Example 110

Quick explanation + ready code for: Classes / Objects.

PHP Classes / Objects Back to examples
Back to language
Syntax: Classes / Objects in PHP. ID: #110

Code

class User{ constructor(name){this.name=name} hi(){return "Hi "+this.name} }
console.log(new User("A").hi());

Notes

You can copy this snippet and adapt it. For advanced, add real-world inputs, edge cases, and tests.