473,854 Members | 1,511 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 4685
Tony Marston wrote:
Why is it so difficult for you to accept that YOUR opinion is not the ONLY
opinion that is allowed to exist? Just because you can quote some people who
agree with you does not make you right. I have quoted from other sources who
agree with me, yet you dismiss all these different opinions as being
"irrelevant ".

Your use of personal insults also shows what a juvenile mind you have.
Why is it so difficult for you to understand that you, with no real OO
experience, and in direct conflict with industry-recognized experts such
as Booch, Jacobson and Rumbaugh, as well as virtually every college
level course on the country, are full of shit?

Because you're stoopid, that's why.

And the insults are because you are too stoopid to understand anything
else, Tony.

People around here are laughing at you. Your stoopidity is beyond
comprehension by anyone with any intellect.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Dec 4 '06 #61
Tony Marston wrote:
"Jerry Stuckle" <js*******@attg lobal.netwrote in message
news:v8******** *************** *******@comcast .com...
>>Tony Marston wrote:
>>>"Jerry Stuckle" <js*******@attg lobal.netwrote in message
news:4q***** *************** **********@comc ast.com...
Tony Marston wrote:
<snip>

>This is a PHP newsgroup, so I am explaining how interfaces work within
>PHP. It is a simple fact that interfaces ARE NOT NECESSARY in PHP. The
>fact that interfaces are treated differently in other languages is
>totally irrelevant. The fact that YOU think that interfaces in PHP
>should behave exactly the same as in other languages is also irrelevant.
>

The subject of interfaces came up in the OO context, not a PHP interface.

However, you're too stupid to understand there's a difference between the
two. So you keep trying to change the subject then justifying your
change - just like any troll.
This is a PHP newsgroup. All my arguments concern PHP. I do not care that
other languages have different implementations because that is totally
irrelevant . The simple fact is that in PHP it is not necessary to use
interfaces .

This discussion has to do with interfaces in the OO context. They are not
the same as PHP interfaces.

But you're too stoopid to understand the difference, so like a troll you
try to change the subject.

Go away, troll.


I am not changing the subject, you are. This is a PHP newsgroup, and my
argument is simply that interfaces are not necessary in PHP. You cannot
disprove this argument, so you attempt to change it to a different argument.
Sorry, Tony. You're even too stoopid to understand the difference
between interfaces in the OO context, which is where this started out,
and the PHP interface keyword.

So you try to change the subject to something else you know absolutely
nothing about, then accuse others of doing the same.

Go back through this thread. Everyone was talking about OO interfaces
before troll Tony Marston stuck his big (and stoopid) mouth in here.

But then you didn't understand the difference the first time; you'll be
too stoopid to understand the difference the second time, also.

People are laughing at you, Tony.
--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Dec 4 '06 #62
Michael Fesser wrote:
.oO(Tony Marston)

>>This is a PHP newsgroup, so I am explaining how interfaces work within PHP.


OK, please do that, no empty promises. Please explain, what interfaces
in PHP are and what you can do with them. Or can't do. I'm listening!

Micha
You notice how Tony refuses to answer your question? It's because he's
too stoopid to respond intelligently.

Have a good laugh with the rest of us - Tony still thinks he (and a few
other unheard of bloggers) are right, and all of the industry-recognized
experts, college professors, experienced OO designers, etc., are wrong.

I'm wondering - does the term megalomaniac ring a bell? Or do you think
it's just that he's beyond stoopid?

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Dec 4 '06 #63
Curtis wrote:
>>Hi, Curtis,


Hello :)

<snip>
>>If these variables are public, you can never change them. But what
happens if you need to - i.e. for performance? Or accuracy?

<snip>
>>Rather, if you encapsulate the longitude and latitude, making them
private, with accessor functions, the data is not hidden - but the
implementatio n is.


I see, I see. All of a sudden, it's like a light bulb turned on in my
head. I have have experience using OOP in PHP, Perl, JavaScript, and
very little in Python and C++, but I am nowhere near an expert,
although I have learned a lot from just trying out code and reading
documentation. There is a lot to OOP I have yet to learn, so I'll try
getting the materials by the experts mentioned. ;)

Just to make sure I interpreted your post correctly:

The benefit of encapsulation is doing things like making certain class
members private, and then utilizing setters/getters so that you can be
much more flexible in changing your class in the future.
Curtis,

Definitely. What you're doing is hiding the implementation of the class
- that is, how the data is stored. The data is still available, via the
accessor functions. But the rest of your program is not dependent on
the internal representation of that data.

Once you've released the class, you can't change or remove anything
that's defined as public (other than to add more to the public
interface). That's because you have no way of knowing who is using it.
You are, however, completely free to change anything declared as
private - because only the class itself can access those items.

The more complex the class, the more important this is. For instance,
there may be a change in the program requirements which necessitates a
change in the data for one reason or another. Or, perhaps there was a
bug in the class itself, and you need to change the data. Or any of a
million different possibilities.

Keeping the data encapsulated ensures any changes to the data only
affect the class itself, and nothing which uses the class.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Dec 4 '06 #64
Tony Marston wrote:
"Jerry Stuckle" <js*******@attg lobal.netwrote in message
news:df******** *************** *******@comcast .com...
>>Curtis wrote:
>>>>That's just your opinion. Where does it say that I *MUST* define and use
an
interface before I can access a class method? Interfaces are optional
(especuiall y in PHP) so it is not wrong to excercise the option NOT to
use
them. I can define a class method and access that method without using an
interface , and that is what I choose to do.
No one is saying that you have to use interfaces. The point is that it
is there to help in organizing and creating classes, the same goes for
visibility keywords. Just because you don't have to use these, doesn't
mean that you should not use them.

I can see an advantage in using interfaces and/or visibility keywords
in PHP, if one is creating a large library, or to help communications
between a team of developers. These features can help track down where
a problem is if something isn't working right, or just for clarifying
the particular usage for the class or its members.

BTW, I do not believe there is any controversy over what encapsulation
is; if so, I haven't heard about it.

Hi, Curtis,

Actually, there is. Tony is claiming that variables should not be private
because they are not part of the implementation.


Wrong again. I did not say that they SHOULD NOT be private, I said that they
DO NOT HAVE TO be private. It is optonal, not mandatory.
Tony, you continue to make a complete ass of yourself. To back into
your little hole, you stoopid troll.
>
>>All of the industry-recognized experts, college level OOAD courses, etc.
disagree with him. So do the people who designed Java.

And even the PHP designers disagree with him - otherwise why would they
have bothered adding private and protected to variables, for instance?


They added those features so that programmers have the option of using them.
Their usage is OPTIONAL, not MANDATORY.
Because you have no idea about what you're talking about. You've been
on one failed OO project - supposedly because those in charge knew less
that you do. You've never taken a class in OO, you've never read any of
the industry-recognized experts on OO (and refuse to do so).

You're just a stoopid troll.
>
>>Data should be private because it hides how the data is being stored. A
SQL database is a perfect example. You can't access the data directly,
but you can do it through SQL. And even if the internal representation of
the data changes (i.e. switch from MyISAM to InnoDB engines in MySQL, or
upgrade MySQL), you can still access the data with no changes to the
program. The data is encapsulated, but it is not hidden (it's all
available).


Now it is you who is being stupid. The way in whch data is stored in the
database has nothing to do with making object variables public, protected or
private. In a well-written application all database access should be
performed in a separate data access object (DAO), thus making it possible to
switch from one database to another (e.g. fom MySQL to PostgreSQL) without
having any effect on the business object.

My argument is that it is not NECESSARY to make every class variable private
or protected. It is an OPTION, but one which does not provide any
additional functionality or increased performance. All it does is place
restrictions on the programmer.
To crawl back into your hole, stoopid troll. You obviously don't
understand encapsulation. And you have no idea what I was talking
about, even though it was in terms simple enough for you to understand.

People continue to laugh at you, Tony. You continue to prove you are
too stoopid to understand your ignorance.
--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Dec 4 '06 #65
Tony Marston wrote:
No, encapsulation is not about making everything private, it is about
putting data and the operations which act upon that data into a single
class. The ability to make certain operations or pieces of data private or
protected is OPTIONAL, not MANDATORY.
I never claimed to summarize the entirety of encapsulation as the act
of making EVERYTHING private, I was merely restating in my own words to
try and clarify my understanding.
I am not saying that you MUST NOT make things private/protected, I am simply
arguing against the statement that you MUST use the private/protected
option. The point is that his is entirely OPTIONAL and is a matter of
personal preference.
You seem to be best friends with the straw man fallacy.
As for saying that you MUST make all data private and access it through
getters and setters, you obviously haven't read
http://www.javaworld.com/javaworld/j...5-toolbox.html
The sources I've gathered, although differ slightly in diction,
generally concur on the meaning of encapsulation. It is true that not
all experts in a field will agree on everything, but the areas in which
there is genuine knowledge are not up for debate or subject to opinion.
You may be confusing semantics for the actual act of implementation, in
this case.

Please don't put words in my mouth. I never said that you MUST do
anything. Honestly, the source you cited is extremely dubious. Nearly
every comment questions Allen Holub's credibility. This is not an
authoritative source, by any means. One commenter even states:

"We have countless of examples of projects / systems that were and are
successful (the Java source code itself being one) using OO concepts
that are contrary to what Holub advocates. In other words, most of us
has been successful doing what he says we shouldn't do and what he
claims won't work well."

It's not my intention to sit here and argue, and I'm sure you have a
retort in waiting, so I'll just go study elsewhere until I have a
decent question that will be of worth to this newsgroup.

Curtis

Dec 4 '06 #66
..oO(Jerry Stuckle)
>You notice how Tony refuses to answer your question?
Yep.
>I'm wondering - does the term megalomaniac ring a bell? Or do you think
it's just that he's beyond stoopid?
I don't know, but actually I don't really care at all. He has just
proven that any attempt to further discuss these things doesn't make
sense. He is always right, the rest of the world is wrong.

I can live with that and draw my conclusions. ;)

EOT
Micha
Dec 4 '06 #67
Tony Marston wrote:
"Michael Fesser" <ne*****@gmx.de wrote in message
news:41******** *************** *********@4ax.c om...
.oO(Tony Marston)
>This is a PHP newsgroup, so I am explaining how interfaces work within
PHP.
OK, please do that, no empty promises. Please explain, what interfaces
in PHP are and what you can do with them. Or can't do. I'm listening!

Micha

It is a simple argument. In PHP interfaces are optional. I *do not* have to
define an interface before I can access a method in an object. The fact that
interfaces may have their uses in specialised circumstances does not get
away from the fact that under normal use they are optional.

--
Tony Marston
http://www.tonymarston.net
http://www.radicore.org
- Interfaces are optional, you don't need to use them to access class
functions.
- Classes are optional, you don't need to define them to use functions
and have reusable code.
- High level languages are optional, you don't need to use them to
access the computer's registers and memory
- All programming languages are optional, you can just write the
machine code directly

Optional != Useless

The whole point of all of these languages, paradigms, and concepts we
have available to us isn't to force you to use them, it's to make the
trivial details disappear so you can focus at a higher level and more
abstract ideas. If you don't want to use them, that's your choice, but
they wouldn't exist if lots of people didn't find them useful.

And if the point you're trying to argue is merely that interfaces are
optional, then I think that's a very silly argument to make. Yes, PHP
doesn't *force* you to use interfaces. You win that point. Way to go.
Next up: I claim that the sky is sometimes blue. Anyone care to
disagree?

- Moot

Dec 4 '06 #68
..oO(Moot)
Next up: I claim that the sky is sometimes blue. Anyone care to
disagree?
The sun is not necessary.
At night it doesn't shine, and during the day it's bright anyway.

SCNR
Micha
Dec 4 '06 #69
Michael Fesser wrote:
.oO(Jerry Stuckle)

>>You notice how Tony refuses to answer your question?


Yep.

>>I'm wondering - does the term megalomaniac ring a bell? Or do you think
it's just that he's beyond stoopid?


I don't know, but actually I don't really care at all. He has just
proven that any attempt to further discuss these things doesn't make
sense. He is always right, the rest of the world is wrong.

I can live with that and draw my conclusions. ;)

EOT
Micha
Yea. But the real problem is - he wouldn't even make a good stand-up
comedian :-)

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Dec 5 '06 #70

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
3638
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
3811
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
3855
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
2376
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
4055
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
9901
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
9752
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11031
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...
0
10371
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
9518
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
7918
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
7082
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
5750
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
4162
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.