473,889 Members | 1,656 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

php 5 classes: public, protected and private

Hi,

finally giving php 5 a go, and going over the new approach to classes.
Can someone clarify the public, private and protected to me?

I quote the php manual: "The visibility of a property or method can be
defined by prefixing the declaration with the keywords: public,
protected or private. Public declared items can be accessed
everywhere."

But should I read "...can be accessed everywhere within a given class."
or "...can be accessed by all other classes." ?

Job

Nov 27 '06
86 4701
Tony Marston wrote:
In PHP interfaces are NOT necessary.
They are how you interact with the object, and

Wrong. You interact with an object by calling an object's method. The fact
that a method may have an optional interface declaration has nothing to do
with it.
I think what's happening here is the unfortunate result of one word
having two different meanings. In this whole argument back and forth
between you two (Tony and Jerry), you each keep using the opposite
definition. Tony interprets "interface" to be the PHP language
construct, while Jerry uses the term "interface" in its object-oriented
context. Neither are wrong, but to have an intelligent, reasonable,
(and hopefully friendly) debate, one needs to define the terms used
beforehand to clear up any confusion.

- PHP language construct "interface" : a construct defined which
declares a set of functions and parameters which must be implemented if
an object claims to use that interface.
- OO concept "interface" : an abstract idea that the member functions
which an object exposes to the outside (ie: public, but not private
functions), comprise the interface to that object through which other
objects may interact with it.

The language construct interface is indeed optional and requires
seperate code specifically written for this purpose. The OO concept of
an interface is *implicit to an object* and requires no additional code
to be written. Any public function of an object is automatically a
part of this interface.

For a physical world example, think of your car stereo. Its interface
(in the OO context) consists of buttons, dials, and a screen (the
public functions which you use to interact with it), while the laser
which reads the CD's and it's power adapter are not part of the
interface (they would be private functions which are used only inside
the class). Now say that it has an iPod connector. In order to make
sure that is sends and receives the correct signals to your iPod, it
must implement some kind of standard, defined by Apple in the (language
construct context) iPod Interface.

So you see? You're both right in your own context. Everybody wins.
Cookies and punch are available in the next room for anyone who wants
to put this semantic pissing match to rest.

- Moot

Dec 6 '06 #81
Moot wrote:
Tony Marston wrote:
>>In PHP interfaces are NOT necessary.

>>They are how you interact with the object, and

Wrong. You interact with an object by calling an object's method. The fact
that a method may have an optional interface declaration has nothing to do
with it.


I think what's happening here is the unfortunate result of one word
having two different meanings. In this whole argument back and forth
between you two (Tony and Jerry), you each keep using the opposite
definition. Tony interprets "interface" to be the PHP language
construct, while Jerry uses the term "interface" in its object-oriented
context. Neither are wrong, but to have an intelligent, reasonable,
(and hopefully friendly) debate, one needs to define the terms used
beforehand to clear up any confusion.

- PHP language construct "interface" : a construct defined which
declares a set of functions and parameters which must be implemented if
an object claims to use that interface.
- OO concept "interface" : an abstract idea that the member functions
which an object exposes to the outside (ie: public, but not private
functions), comprise the interface to that object through which other
objects may interact with it.

The language construct interface is indeed optional and requires
seperate code specifically written for this purpose. The OO concept of
an interface is *implicit to an object* and requires no additional code
to be written. Any public function of an object is automatically a
part of this interface.

For a physical world example, think of your car stereo. Its interface
(in the OO context) consists of buttons, dials, and a screen (the
public functions which you use to interact with it), while the laser
which reads the CD's and it's power adapter are not part of the
interface (they would be private functions which are used only inside
the class). Now say that it has an iPod connector. In order to make
sure that is sends and receives the correct signals to your iPod, it
must implement some kind of standard, defined by Apple in the (language
construct context) iPod Interface.

So you see? You're both right in your own context. Everybody wins.
Cookies and punch are available in the next room for anyone who wants
to put this semantic pissing match to rest.

- Moot
Moot,

The problem is the original discussion was about interface in the OO
concept. But Tony knows nothing about OO, other than what he's read in
a few blogs by unknown authors of dubious credibility. So he tries to
take it into something he has never used, but can look up easily - the
PHP interface keyword.

I'm just not letting him change the subject.

It would be refreshing if he knew anything. But he obviously has no
clue what he's talking about - even in the case of a PHP interface.

He's just a troll with delusions of competency.
--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Dec 7 '06 #82

"Jerry Stuckle" <js*******@attg lobal.netwrote in message
news:uK******** *************** *******@comcast .com...
Tony Marston wrote:
>"Jerry Stuckle" <js*******@attg lobal.netwrote in message
news:he******* *************** ********@comcas t.com...
>>>Tony Marston wrote:

"Michael Fesser" <ne*****@gmx.de wrote in message
news:4u**** *************** *************@4 ax.com...
<snip>
>>>>I am not wrong. I have made two simple statements that you cannot
disprove:

(a) In PHP interfaces are not necessary.
(b) Enapsulation does not mean that all variables must be declared
private or protected.

What's so difficult to understand about that?
You're wrong because:

(a) Interfaces, as defined in OO terms (which is what we were
discussing, and PHP is an OO language) are necessary.

In PHP interfaces are NOT necessary.
>>They are how you interact with the object, and

Wrong. You interact with an object by calling an object's method. The
fact that a method may have an optional interface declaration has nothing
to do with it.

And in OO terms that is the INTERFACE! But you don't know anything about
OO, that's obvious.
You are confusing the term inetrface (as in Application Programming
Interface or API) with the construct that uses the word "interface" and
"implements ". An API is simply a function name with a list of arguments,
while interfaces are hings which exist in addition to the function
definition.

It is a simple fact that I can access an object's method by using the
function definition (API) and NOT tghe piece of code which contains the word
"interface" .

The terms API and interface in OO terminology do not mean the same thing.
>>
>>(b) Proper encapsulation means that all variables are defined as
private,


Wrong. Encapsulation simply means putting all the data for an object, and
the operations which act upon that data, into a single class. There is no
requirement to make all the data private, as there is no requirement to
make any methods private.

Wrong again, Troll Tony.
My definition of encapsulation is not wrong What is your definition?

I still stick to my original statements:

(a) In PHP interfaces are not necessary.
(b) Encapsulation does not mean that all variables must be declared private
or protected.

--
Tony Marston
http://www.tonymarston.net
http://www.radicore.org
Dec 7 '06 #83
There is a big difference between interface as in API (Application
Programming Interface) and interface as an OO construct which contains the
words "interface" and "implements ".

In PHP I can access an object's method through its API, and I do not need
that additional declaration that contains the word "interface" .

Simple, isn't it?

--
Tony Marston
http://www.tonymarston.net
http://www.radicore.org

"Moot" <mo************ *******@yahoo.c omwrote in message
news:11******** **************@ 73g2000cwn.goog legroups.com...
Tony Marston wrote:
>In PHP interfaces are NOT necessary.
They are how you interact with the object, and

Wrong. You interact with an object by calling an object's method. The
fact
that a method may have an optional interface declaration has nothing to
do
with it.

I think what's happening here is the unfortunate result of one word
having two different meanings. In this whole argument back and forth
between you two (Tony and Jerry), you each keep using the opposite
definition. Tony interprets "interface" to be the PHP language
construct, while Jerry uses the term "interface" in its object-oriented
context. Neither are wrong, but to have an intelligent, reasonable,
(and hopefully friendly) debate, one needs to define the terms used
beforehand to clear up any confusion.

- PHP language construct "interface" : a construct defined which
declares a set of functions and parameters which must be implemented if
an object claims to use that interface.
- OO concept "interface" : an abstract idea that the member functions
which an object exposes to the outside (ie: public, but not private
functions), comprise the interface to that object through which other
objects may interact with it.

The language construct interface is indeed optional and requires
seperate code specifically written for this purpose. The OO concept of
an interface is *implicit to an object* and requires no additional code
to be written. Any public function of an object is automatically a
part of this interface.

For a physical world example, think of your car stereo. Its interface
(in the OO context) consists of buttons, dials, and a screen (the
public functions which you use to interact with it), while the laser
which reads the CD's and it's power adapter are not part of the
interface (they would be private functions which are used only inside
the class). Now say that it has an iPod connector. In order to make
sure that is sends and receives the correct signals to your iPod, it
must implement some kind of standard, defined by Apple in the (language
construct context) iPod Interface.

So you see? You're both right in your own context. Everybody wins.
Cookies and punch are available in the next room for anyone who wants
to put this semantic pissing match to rest.

- Moot

Dec 7 '06 #84
Tony Marston wrote:
"Jerry Stuckle" <js*******@attg lobal.netwrote in message
news:uK******** *************** *******@comcast .com...
>>Tony Marston wrote:
>>>"Jerry Stuckle" <js*******@attg lobal.netwrote in message
news:he***** *************** **********@comc ast.com...
Tony Marston wrote:
>"Michael Fesser" <ne*****@gmx.de wrote in message
>news:4u*** *************** **************@ 4ax.com...

<snip>
>>>>>I am not wrong. I have made two simple statements that you cannot
>disprove :
>
>(a) In PHP interfaces are not necessary.
>(b) Enapsulation does not mean that all variables must be declared
>private or protected.
>
>What's so difficult to understand about that?
>

You're wrong because:

(a) Interfaces, as defined in OO terms (which is what we were
discussin g, and PHP is an OO language) are necessary.

In PHP interfaces are NOT necessary.
They are how you interact with the object, and

Wrong. You interact with an object by calling an object's method. The
fact that a method may have an optional interface declaration has nothing
to do with it.

And in OO terms that is the INTERFACE! But you don't know anything about
OO, that's obvious.


You are confusing the term inetrface (as in Application Programming
Interface or API) with the construct that uses the word "interface" and
"implements ". An API is simply a function name with a list of arguments,
while interfaces are hings which exist in addition to the function
definition.
You really don't know anything about OO, do you, Tony. Not even the
most basic terminology.
It is a simple fact that I can access an object's method by using the
function definition (API) and NOT tghe piece of code which contains the word
"interface" .
Stupid troll doesn't understand basic OO.
The terms API and interface in OO terminology do not mean the same thing.
You really don't know OO terminology, Tony. I suggest you at least read
up on the basics of OO - from a RESPECTED SOURCE, not your favorite blog
entries.

You only continue to make a huge fool of yourself. But you're only a
stupid troll, so that's only to be expected.
>
>>>>(b) Proper encapsulation means that all variables are defined as
private,
Wrong. Encapsulation simply means putting all the data for an object, and
the operations which act upon that data, into a single class. There is no
requiremen t to make all the data private, as there is no requirement to
make any methods private.

Wrong again, Troll Tony.


My definition of encapsulation is not wrong What is your definition?

I still stick to my original statements:

(a) In PHP interfaces are not necessary.
(b) Encapsulation does not mean that all variables must be declared private
or protected.
You really don't understand even the most basic elements of OO
programming, Tony. You're just a troll.

Read from RESPECTED RESOURCES. Then open your mouth. You're only
making a bigger fool of yourself, and people are laughing at you.

What little credibility you ever had in the newsgroup is virtually all
gone now. You've made too much of an ass of yourself for anyone to take
you seriously.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Dec 7 '06 #85
Tony Marston wrote:
There is a big difference between interface as in API (Application
Programming Interface) and interface as an OO construct which contains the
words "interface" and "implements ".

In PHP I can access an object's method through its API, and I do not need
that additional declaration that contains the word "interface" .

Simple, isn't it?
Yep, you've once again shown you don't understand even the basic
terminology of OO programming, Tony.

Tony the Troll once again makes a complete ass of himself.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Dec 7 '06 #86
Jerry Stuckle wrote:
>
Tony the Troll once again makes a complete ass of himself.

I don't mean to be rude, but you aren't showing yourself in too good of
a light right now, either, by prolonging this argument.

If I didn't believe you way back in the beginning when you said he was
just trolling, I sure do now. But what's the #1 rule for trolls?
Don't feed them.

I'd like to thank the both of you for making my workday a slight bit
more entertaining the past week or so, but I've just about had my fill
of this thread. I suggest that you stop caring about getting the last
word and just let it die. At this point, I think everyone realizes who
knows what he's talking about and who doesn't.

- Moot

Dec 7 '06 #87

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
1813
by: verbatime | last post by:
Please explain me how this works - or should work: Got my two classes - bcBasic (baseclass) and the derived cBasic. //--------------------------------------- class bcBasic { int number; virtual long myfunc(void); }
45
3640
by: Steven T. Hatton | last post by:
This is a purely *hypothetical* question. That means, it's /pretend/, CP. ;-) If you were forced at gunpoint to put all your code in classes, rather than in namespace scope (obviously classes themselves are an exception to this), and 'bootstrap' your program by instantiating a single application object in main(), would that place any limitations on what you could accomplish with your program? Are there any benefits to doing things that...
3
2068
by: Bryan Parkoff | last post by:
I have C++ Primer Third Edition -- Author Stanley B. Lippman and Josee Lajoie. I have been studying it for couple months however it does not provide a valuable information which it is about "friend to class". I am very disappointed because it is the way how C++ Compiler is designed. I assume that "friend to class" is not the good option. If CMain class is initialized before CA class, CB class, and CC class are initialized inside CMain...
14
3813
by: Pratts | last post by:
I am a new one who have joined u plz try to help me bcoz i could not find ny sutiable answer foer this Question Qus>>why do we need classes when structures provide similar functionality??
6
3370
by: steve bull | last post by:
I created a usercontrol class, RGBColorSpace, which is derived from an abstract class, ColorSpace, but when I try to click on the design panel for the control I get an error message "Unable to create instance of abstract class ColorSpace". I never try to create a class ColorSpace and don't really want to create a regular class with virtual methods. Does anyone know why I am having this problem? The code seems to run fine and I can actually...
11
3858
by: Kevin Prichard | last post by:
Hi all, I've recently been following the object-oriented techiques discussed here and have been testing them for use in a web application. There is problem that I'd like to discuss with you experts. I would like to produce Javascript classes that can be "subclassed" with certain behaviors defined at subclass time. There are plenty of ways to do this through prototyping and other techniques, but these behaviors need to be static and...
5
2011
by: Chris Szabo | last post by:
Good afternoon everyone. I'm running into a problem deserializing a stream using the XmlSerializer. A stored procedure returns the following from SQL Server: <Student StudentId="1" Status="1" Gpa="3.50"> <Person Id="1" FirstName="FirstName0" LastName="LastName0" MiddleInitial="W"/> </Student> In my code, person is the base class and student extends it. When I
2
2378
by: miked | last post by:
I am architecting in a read only class for use in mapping data to a business object. The object makes strong use of nested classes and their ability to access protected fields. The downside is when a nested class inherits from it’s parent class you get this infinite class chain in intellisense when consuming the class. To get around this I created two child classes Reader and Writer which require a base Person object. When consuming...
47
4060
by: Larry Smith | last post by:
I just read a blurb in MSDN under the C++ "ref" keyword which states that: "Under the CLR object model, only public single inheritance is supported". Does this mean that no .NET class can ever support multiple inheritance. In C++ for instance I noticed that the compiler flags an error if you use the "ref" keyword on a class with multiple base classes. This supports the above quote. However, under the "CodeClass2.Bases" property (part...
0
9969
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
11203
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10896
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10443
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9612
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7999
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7151
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6029
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4251
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.