Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Definitions and Theory (Part I) - Is this right?

Posted on 2014-11-07
Medium Priority
Last Modified: 2014-12-02
Some questions and answers that I've assembled in an effort to better understand OOP. If you could read through them and either affirm my answers as correct, or alert me to my being less than accurate...

Here we go:

What's a Construct?

A construct is a function that you use to define properties in the context of your class.

What's an Accessor?

An Accessor is a function that is used to define a Property for a Class. The Property has to be assigned a visibility value of "private' in order for it to work, but this is a handy way to manipulate Property values within a Class (http://coursesweb.net/php-mysql/php-oop-accessor-destructor).

What's the difference between Construct and Accessor if they're both used to define a Property?

(I'm weak on this one...)

Flexibility. With an Accessor you can make changes on the fly, but with Construct, you're establishing a programmatic foundation that doesn't allow for the Property values to be changed as easily...?

I'll be posting several questions today in the context of "Definitions and Theory." Feel free to weigh in however and whenever you would like. Thanks in advance for helping me get my mental arms around all of this...?
Question by:brucegust
  • 2
  • 2
LVL 111

Expert Comment

by:Ray Paseur
ID: 40429012
If you can, please post the links to the material you're asking about.

The "Accessor" concept is also called "setters and getters" since it provides a formalized way of adding/updating and retrieving data from an object.

If by "Construct" you really mean "Class Constructor" it's simply a function (method) that is run when an object is instantiated from a class.  You do not necessarily use it to define properties.  It just takes care of "housekeeping" tasks at instantiation time.
LVL 111

Accepted Solution

Ray Paseur earned 2000 total points
ID: 40429026
Eww, one other note.  I've only been looking at it for a few minutes and I've already found some pretty serious errors in coursesweb.net.  You might want to step back from that questionable site and start by reading the information from the horse's mouth:


If you like books, these two are worth your time and money:

Author Comment

ID: 40429062
I do like books, Ray, but I find that I learn best by "doing," and while I don't have a completed page or link to show you yet, I hope to be there within the next several hours, but not at the expense of being able to understand "why" what I've coded is correct.

As far as "construct"...

Based on your counsel and this link: http://php.net/manual/en/language.oop5.decon.php, what I'm perceiving is that while Construct can facilitate the definition and Property values, it can be used to establish any one of a number of crucial starting points. To use your verbiage, it's "housekeeping" and the definition of Property values is but one of the things that fall under that heading.


Author Comment

ID: 40429102

Property accessors provide a clean, easy to understand and unified syntax for get/set accessors. They allow read and write requests (gets and sets) from a class property to be run through a method first. This method can perform validation or a transformation, or update other areas of the class. Properties do not even have to be associated with a class member, and can generate their own data on-the-fly. (https://wiki.php.net/rfc/propertygetsetsyntax-v1.2)

Whereas "construct" can be used to facilitate any one of a number of "housekeeping" tasks, an Accessor's role is focused exclusively on Class Properties.

It's a handy tool to have in that you can establish "starting points" on the fly and in that way preserve an adaptive dynamic to your functionality.

I don't have an example of this yet. It was mentioned in some documentation as an aside and I wanted to understand what it was.

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days socially coordinated efforts have turned into a critical requirement for enterprises.
This article discusses how to create an extensible mechanism for linked drop downs.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question