- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
Oh boy, this title.
Also, obligatory :giggity:
Admin
I was expecting something Flash related. This is... somehow worse.
Admin
I've seen Java's reflection being used before to get access to private methods. This is... different.
Admin
Wow, this is like C++
#define private public
but in PHP...holy crap...[image] Looks like Paula is getting slower.
Admin
#WHY‽‽‽
Admin
The cornify link is in an HTML comment? I, uh, don't think that's going to do what you meant it to do.
Admin
Now if I ever write a PHP class, I'll do something like
*PHP is very rusty, this is probably broken
Admin
Defensive coding at its finest. :P
Admin
Best defense is a good offense :smile:
Admin
I'm not entirely sure without bothering to test, but I'm inclined to believe it does slightly more than that:
What would that do with
echo "This is the private section\n";
Admin
Aww, I was hoping somewhere in the code the word
public
would be typo'd.Admin
In the
privates
section?Admin
If I ever see code like that in anything I'm working on, I'll be arranging a meeting with the developer responsible in a quiet alleyway, and I'll be taking one of these: [image]
Admin
I can give you one reason you might do this, though I'd hope the implementation would be slightly less retarded than this.
What if you're a project that wants to do things in a PHP 5 way but have a certain amount of PHP 4 userbase that won't migrate? I say this because SMF did exactly this, albeit in a slightly nicer and much more reliable way than this for the 2.0 series that had PHP 4 compatibility long after PHP 4 EOL'd because of slow release cycles.
Admin
Yikes!
Evil exec() combined with 'object orgy' and blind regexp, I would never have thought I'd see that particular combo...... (I've not used PHP, so I do not know if the PATH variable can be changed by user input, but if so, then as an added bonus you have a (potential) code injection vulnerability also)
Admin
I want to see how this code is used
Admin
PATH in there is a constant, so I'd hope not but it's not impossible to have a constant set based on user input.
Admin
Meh, just a clbuttic bug, the QA can deal with that.
Admin
Finally some useful tricks to handle these new PHP5 libraries who violate Open Source with all their hidden properties!
Fight privatization. Free PHP!
Admin
If it wasn't obvious, that is.
It's even more fun when a method called myPrivateMethod() - GUESS WHAT HAPPENS! Now try calling them from the outside.
Sure, you might have a problem with variable names but that's only if you reference them from outside the file. However, nobody would be using global variables, right?
Admin
Nothing? It has a capital P, and the word boundaries wont match.
Admin
Ah but say they have
my_private_method
?Admin
Ah, right, Forgot about that. Yeah, nothing would actually happen. It's not as bad as I thought, but whatever - still not good.
Admin
Nope.
http://www.regular-expressions.info/wordboundaries.html
http://www.regular-expressions.info/shorthand.html
Admin
But this is TRWTF, PHP, so anything's possible. Though PCRE is more sane, I guess. I forgot that _ was considered a word character.
Admin
Whitebox testing. There are cases where I do a similar (albeit simpler) thing in C++ CPPUNIT:
#define private public #include <ClassImTesting.h> #undef private
Now my tests can peek into the state of objects under test...at the cost of some maintainability if the shape of the internal data changes.
Admin
ERR_INCOMPATIBLE_FORUM_TYPE
Admin
I like the invention of the new word publicified. Publicify, privatify, protectify.
Admin
TR :wtf: is that we already have the word publicized (and privatized as well). Although protectedized hasn't yet been worded.
Admin
Surely the conjugation would be protectized rather than protectedized ?
Admin
Where's that
:tongue_in_cheek:
emoji?Admin
You're on a forum full of gramming and spellar pendants, what did you think would happen?
Admin
You'd like to think so, but we have abominations like "administrated", so....
Admin
Another reason for compiled languages!
Now, if this was done every time the application renders a page... oh boy!
Admin
It probably is done every time the application renders a page. PHP is great like that.
Admin
English as a compiled language? Hmm…
Admin
Pretty much everyone would be making syntax errors all the damn time.
Though the idea that 'YOUR' used incorrectly would fail with an error appeals greatly to me.
Admin
BadHomonymException
?Admin
That would imply it was a run-time problem as opposed to compile time syntax error.
Admin
It depends: is the speaker statically or dynamically typed?
Admin
well, i have always thought that english was rather duck-typed.
if it looks like a duck, walks like a duck, and quacks like a duck, then it's a monster truck entering a compact car class demolition derby.
... wait. what?!
Admin
Admin
I've seen something similar done with java... but with all classes and without making new ones.
Admin
Actually not as mad as you would think: https://en.wikipedia.org/wiki/DUKW I suspect that one would do rather nicely in a compact car class demolition derby. It wouldn't even have a problem with a trip in a pond..... :grin:
Admin
My favorite variable name I ever used came from writing software for group picnic bookings (about 1999). Packages included options for Food, Sodas (called "drinks"), and a Beer & Wine option. It had very custom logic for everything, so variables were prefixed with Food, Drink etc. (VB6 - more variables less object). In any case I got tired of these long BeerAndWine variables and just shortened it to "booze". Trust me, coding becomes a lot more fun whet you get to type and check for the value of "booze" everywhere.
(yes, my code probably had a lot of WTF in it, but it was my first real SQL exposure and I was dealing with an ODBC driver where left outer joins was broken - and this was an ongoing release note).
Admin
Besides being horrible code, I see nothing wrong with it — assuming it's used for the right purposes. For example, when writing a unit test to confirm internal state changes according to specs, or when planning a refactoring, access modifiers are just in the way (in the sense of creating cost without adding value). Then a "#define private public" is well justified — and even beneficial, because it avoids accidentally leaking a wrong access modifier into production.
If used in production, it's a reason to get fired though :).
Admin
Admin
Syntax error on line 1.
Admin
That's a whole lot better than the stupidity that is 'burglarize', though.
:shudder
Admin
What about 'spoilerize'?