Solved

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

Posted on 2014-11-07
4
60 Views
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...?
0
Comment
Question by:brucegust
  • 2
  • 2
4 Comments
 
LVL 109

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.
0
 
LVL 109

Accepted Solution

by:
Ray Paseur earned 500 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:

http://php.net/manual/en/language.oop5.php

If you like books, these two are worth your time and money:
http://www.amazon.com/PHP-Object-Oriented-Solutions-David-Powers/dp/1430210117
http://www.amazon.com/gp/product/143022925X/
0
 

Author Comment

by:brucegust
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.

Better?
0
 

Author Comment

by:brucegust
ID: 40429102
Accessors...

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.
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

774 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