Solved

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

Posted on 2014-11-07
4
59 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 108

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 108

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
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…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

896 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now