Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Cover image for PHP __construct (🧙‍♂️Lesson 1: PHP Magic Methods)
Clean Code Studio
Clean Code Studio

Posted on • Edited on

     

PHP __construct (🧙‍♂️Lesson 1: PHP Magic Methods)

Twitter Follow


Today, we'll quickly cover the most popular PHP magic method -__construct.


__construct magic method


PHP allows developers to declare constructor methods for classes. Classes which have a constructor method call this method on each newly-created object, so it is suitable for any initialization that the object may need before it is used.


Using the PHP __construct magic method


<?phpclassUser{public$name;publicfunction__construct($name){$this->name=$name;}}$timmy=newUser('Timmy');echo$timmy->name;// "Timmy"
Enter fullscreen modeExit fullscreen mode

__construct PHP Magic Method



Did you know I have a newsletter? 📬

If you want to get notified when I publish new blog posts or make major project announcements, head over to

https://cleancodestudio.paperform.co/

Top comments(1)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss
CollapseExpand
 
cleancodestudio profile image
Clean Code Studio
Clean Code Clean Life ~ Simplify
  • Email
  • Location
    Las Vegas, Nevada
  • Education
    Self Taught
  • Work
    Senior Software Engineer - Anaconda, Inc.
  • Joined
unknown tweet media content
Clean Code Studio ☕ profile image
Clean Code Studio ☕
twitter logo
Welcome to the#CleanCodeStudio thread, of threads - with more threads. (AKA#ASimpleThread)

Discover developer threads on#php,#js,#vue,#Laravel,#algorithms,#datastructures,#tooling#faang,#refactoring,#design,#cleancode, & more!

FILL UP ☕
POWER UP💻
DIVE IN BELOW👇
03:16 AM - 30 Jul 2021
Twitter reply actionTwitter retweet actionTwitter like action

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Clean Code Clean Life ~ Simplify
  • Location
    Las Vegas, Nevada
  • Education
    Self Taught
  • Work
    Senior Software Engineer - Anaconda, Inc.
  • Joined

More fromClean Code Studio

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp