0

in PHP4 there is no public,private,etc. So I am wondering if there is some sort of work-around so that I can make a class's property private and only accessible via getter/setter

Thanks!!

6
  • 3
    Why are you still using PHP4? It was discontinued three years ago! us.php.net/archive/2007.php Commented Feb 11, 2010 at 19:49
  • That's the most important question. Is this about language theory, or about writing actual new code? Commented Feb 11, 2010 at 20:10
  • 1
    A huge number of shared hosts still only support PHP 4 its not always feasible to upgrade easily to PHP 5. Legacy still needs maintenance. Commented Feb 11, 2010 at 20:24
  • @Toby Allen .. any site that hasn't upgraded yet are worth leaving, customers need to send a message to crappy hosts. We're not talking about weeks or months, we're talking about YEARS of a discontinued product that's free for them to upgrade. he only barrier is their own laziness, not to mention the speed improvements (means more customers per server) and security fixes. Commented Feb 11, 2010 at 20:58
  • 1
    @TravisO The primary reason why providers don't upgrade is the fear of a lynch mob burning down the data center when hundreds of PHP4 applications suddenly stop working, or start behaving funny. Still, PHP4 had its time, we all loved it and now it needs to be put to sleep. Legacy applications really should be ported because the security risks continuing to run them on an unsupported platform are enormous. See stackoverflow.com/questions/1734072/… Commented Feb 11, 2010 at 21:40

4 Answers 4

5

You could approach this with a distinct syntax that clearly discourages the usage of such properties. You could borrow the python syntax of starting the method name with an underscore to define it as private.

This doesn't block anyone from using it, of course, but its usage will be discouraged.

Sign up to request clarification or add additional context in comments.

Comments

3

You can't. Since the property is itself public, anyone can access it without getter / setter preventing you from actually performing any checks in between.

Comments

2

Can't be done, sorry.

It's certainly possible to build a workaround by building own getter and setter functions and keeping a table of which property is private/public/protected, but it's hardly worth the effort anymore, is it? PHP 4 is really outdated, see here.

Comments

2

you can still write getters and setters for that variable, but there is no way to make a function private in PHP 4.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.