- 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
I haven't used PHP, but Ruby also doesn't (by default) use === in the same way PHP seems to (which, from what I gather, involves a type comparison in PHP). === in Ruby has to do with ranges/matches. I believe it's used behind the scenes in case statements, which is what lets you do stuff like use a range as a match condition when switching on a number, or a regex when switching on a string. (1..2) doesn't equal 2 so (1..2) == 2 is false, but 2 is within the range of 1 to 2, inclusive so (1..2) === 2 is true. Same idea with regexs. To compare types of two objects in Ruby you'd do something like 2.class == 2.0.class (which is false).
It can be overloaded, though, so someone would be free to implement === to do whatever they wanted (please don't!).
Admin
Admin
Hey, a $1,000 is a $1,000 right? Works for me.
Jiff www.anonymize.us.tc
Admin
That code will return "Parse error. Missing parenthesis." - or something of the likes :)
Admin
Fixed.
$price = preg_replace('/[^0-9.]/', '', $price);
Admin
Admin
Admin
This is what locale functions are for!
Admin
Huh? StringBuffer has been there for essentially forever (since 1.0) while StringBuilder has only been added in Java 5 because in most cases, people were using StringBuffer in a single thread and were paying the cost of synchronization for nothing...
Admin
Perhaps we can write a program to randomly generate every possible PHP function, save its output, and include it in every program. Then you just find the function you want and call it. We could call it "the library of Babel". :)
Admin
Oh get off your high horse already; 3MB is a small price to pay for a stable, reusable library that probably cuts development time in half.
Admin
This find-first-occurance-starting-at-index and string-concatenation approach will be faster than a dozon str_replace() calls any day, but speed alone doesn't matter to some here.
Once I made a multiple replace function. It could be used for general string swapping without a reserved intermediate string replacement. I made it to do replacement of batchfile-type variable names with constants before evaluating it. (Yes I had properly escaped the constants first.) Multiple calls to replace can't accomplish this without reserved strings and risking undesired nested expansion that's dependent on the order of the calls.
Admin
TRWTF in your comment is that array() is not a function, but rather a language construct. ;P
Admin
I'm old enough that my "big honking file" has routines that predate the VB functions they are 're-writing'. For example, Replace().
Even recently I wrote routines to strip off the time or date from a DateTime, only to find that there are built in .TimeOfDay and .Date functions as part of the Date type. Dunno when they got added. Maybe they were there all along.
When I started programming, there wasn't any such thing as a date variable :-O I had my own routine to parse a date string into an integer (which represented the number of days since a certain magic date).
(Actually I remove functions from my big honking file as they become redundant, but it's funnier to claim they are still there)
Admin
Seven days if I remember correctly.
Admin
Admin
Captcha facilisis thinks that given solution is TRWTF. What will be if user enters $1000.25? 100025? OOPS. Someone really screwed up.
Admin
it was an answer to
Admin
Ouch, there is truth to this... SO, the solution is to get rid of all fixString() calls and replace them with str_replace() everywhere they reside, while carefully considering differences in behavior. :)
What a utopia, right? What's the ROI from the fast-paced business's business peoples' perspectives?
Although it is really worth it in the long run. It benefits both employees, the companies, and overall morale. Working on plugging holes in sinking ships is not conducive to employees, the companies, and overall morale.
I advocate battling past office politics.
Admin
[quote user="Matt"][quote user="cod3_complete"] 2. No exceptions (in PHP4 which everyone still uses) [/quote]
For certain values of everyone maybe...for the rest of us, we are reading up on PHP 6 after several years on PHP5.
Admin
That would make it, "1,00000"... yay for accidentally multiplying it by 100.
Admin
That was in reponse to this, naturally:
Admin
As Matt points out a real job is one where you are allowed to exceed a whole THOUSAND LINES of code!!!!! or writing maintaiable code.
No you don't need to wonder anymore
Admin
Indeed, it was built in 6 days, and the 7th was a day of rest.
Admin
You are going to write separate str_replace() for each input field? What about if they want to filter eg thousand separator? Another str_replace() for each field? It is not brilliant (and not secure) but this is why they have some lib for 'everything' :))
Admin
Good point. On second thought, the worst case complexity seems to be "only" O(n² + nm). Of course, strictly speaking this doesn't contradict my previous notion. ;-)
Admin
[quote user="abx"][quote user="Juifeng"]the culture of the computer it runs off could be assumed[/quote]
Great. We'll use IP geolocation for that!
Admin
Clueless.
Admin
Admin
And now the company goes international and deals with real currencies like Yen, Euro, Pounds and what not. And there goes the site, down again because Jared did not want to listen to the more experienced teamlead who did in fact envision other characters to be excluded as well. Perhaps not as efficient as possible, but it would work... but noooo.... not Jared... eh, Jared?
Admin
Agreed, but have you ever heard of lock elision ... ?
Admin
"Jared shook his head and sighed. Instead of including the entire, 800-line everything.inc file in his page, he opted for the built-in replace():"
Go forbid that he would consider simplifying "fixString" at the same time. Or stripping its usage out of the existing system.
Why is it that so many WTFs end with papering over the cracks and moving on?
Admin
I do work most every day in php, among other languages, and tbh i have never encountered documentation on a function with incorrect number of arguments. I'm not saying your claim is or is not true, but only that I've never encountered it, and this is not due to that I have no need to use a generous range of the available functionality of the language.
If you find such a thing, make yourself useful and submit a bug report to the documentation team that works as volunteers and someone will check it out and make the changes in cvs. If ever in doubt, one can always look at the source to see the internals, but like I mentioned, I've never encountered this and tbh I feel you are exaggerating for dramatic impact the frequency of something like this happening.
Admin
What happens when you write "£1,000.00" .....
Admin
Admin
Community organizer.
Admin
We ignore the punctuation, interpret what's left as an integer, and bill the customer's credit card for one hundred thousand dollars. So what's the problem?
Admin
Anyone in the audience with the power of telekinesis, please raise my hand.
Admin
Wow, talk about an inside joke. I feel a certain irrational smugness for catching the allusion, like, "Ooh, I wonder how many readers here even know who Elisha was." Why is understanding an inside joke emotionally gratifying? An amusing psychological study. Perhaps I can get a government grant to research it.
Admin
TRWTF is using array('$') instead of '$'.
Just because str_replace() can take an array instead of a string doesn't mean you should randomly build a single-element one and pass that in.
Also ltrim() might have been a better solution. OTOH, it wouldn't handle -$20, so maybe not.
Also, I at least consider it best practices to use single quotes instead of double quotes for stuff that isn't supposed to have variables evaluated in it, although that's not that important.
Admin
Admin
Fight, Fight Fight Fight! LOL Fight!!!!!
Jiffers www.anonymize.us.tc
Admin
Admin
And even that is verbose:
$str = ltrim($str, '$');
Admin
Admin
Admin
Admin
This is a classic case of reinventing the wheel when unnecesary (and possibly slow and dangerous).
The worst such case was code I saw which worked on a PostgreSQL server I was paid to install. All of the code was in stored procedures and all of the stored procedures which inserted new records did something like this to create a new ID number.
SELECT INTO newid MAX(id) FROM table; SELECT INTO newid newid + 1;
It might have been creative, but it was slow and buggy, causing lots of duplicate errors and really straining the database (since MAX is slow due to postgres' form of concurrency).
Admin
floatval();
Admin
This is Hamlet Shoes Trading Co. LTD., which is united by lots of footwears manufacturers in Fujian of China. We deal with brand shoes like Nikes, Adidas, Puma, Timberland boots, etc. We have especially Nikes like Air Jordan retro,nike shox (Nz Oz R3 R4 R5 Turbo), Air Max (LTD TN 90 95 97 2003 2004 2005 180 360), Air force one,James, Dunks,and other products: bape, prada,Gucci shoes, jeans,handbags, lacoste,polo,bape jacket and so on. We can supply mixed colours and sizes as you like. Drop shipping can be done also. Normally we need 24 working hours to process your order after receipt of payment. You can expect to receive the shoes in around 5-7days. Buyers please feel free to contact us: E-mail & MSN: [email protected] Browse our website:http://www.wholenike.com. We are waiting for you. Best regards!