1. 42
    Retrieve public class properties with PHP’s arrow syntax
    1m 43s

Retrieve public class properties with PHP’s arrow syntax

Mark Shust
InstructorMark Shust
Share this video with your friends

Social Share Links

Send Tweet
Published 2 years ago
Updated 2 years ago

Creating class properties is useless unless you can read back that property! There's an easy way to do this, with PHP's shorthand arrow syntax.

Instructor: [0:00] We already created a constructor in this Author class which executes when a class is created or instantiated. Since this name class property has a public visibility, we can refer to it directly with a special arrow syntax on the created object instance.

[0:20] Let's go back to our functions.php file and we will name this variable author1. We will actually create a second instance of the author object, and let's name this Betsy Sue.

[0:36] We can now assign properties of these created objects to new author indexes on the POST array. Let's go to this first array element and we will create a new author index. This will be assigned a value of author1 => $name. We can reference this name class property directly since it is public in scope. Let's do the same thing for this second blog article. In the third one, we will reference author2's name.

[1:14] We want to display the author on our blog post listing page. Let's go back to the index.php file, and let's create a new line for the byline. We will refer to the author index that we just created.

[1:32] When we refresh the page, we will see that it grabs the instance of the name class property from both the newly created PHP objects.

~ a minute ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today