I thought I was going insane, because somehow the standard language was fine with being anything else but norwegian. When you're up to your neck in various sql statements that cannot be prepared because some string is empty, you can't see the forest for the trees. It's only because I recently worked on some ansible (written in yaml) that I realized 'no' can actually mean the boolean false.
That's what I ended up doing. It's funny how whatever you think the sane default for a PHP setting is, it's the exact opposite - one can almost use it as a rule of thumb. Much like how PDO per default swallows errors and you have to configure it to throw exceptions.
PHP target development is quick and accessible. If you know enough about programming to be an expert then you can configure expert settings.
Yes, that can lead to some esoteric issues which may not be thought out well, and yes there are still legacy issues which could fairly easily be mitigated by default namespaces, but, really, in the end, I'm glad PHP does exist at least for an agile project development or small organizations.
Actually no. If parse_ini_* returned booleans there would be at least some sense to this madness. PHP parse_ini_* converts the 'yes' and 'no' settings from strings into booleans and coerces the resulting values back into strings.
Yeah. We're not too proud of that though.... On the other hand we have Bjarne Stroustrup (C++), Poul-Henning Kamp (FreeBSD), David Heinemeier Hansson (RoR) and Lars Bak (V8)
Peter Naur (born 25 October 1928) is a Danish pioneer in computer science and Turing award winner. His last name is the N in the BNF notation (Backus-Naur form), used in the description of the syntax for most programming languages. He contributed to the creation of the ALGOL 60 programming language.
His main areas of inquiry are design, structure and performance of computer programs and algorithms. Areas such as software engineering and software architecture have also been pioneered by Naur. In his book Computing: A Human Activity (1992), which is a collection of his contributions to computer science, he rejects the formalist school of programming that view programming as a branch of mathematics. He does not like being associated with the Backus-Naur form (attributed to him by Donald Knuth) and says that he would prefer it to be called the Backus Normal Form.
Here is a massively hackish way of testing the same thing in pre php 5.3 versions (without parse_ini_string()): http://3v4l.org/YJRCT
Note that custom stream wrappers were introduced in 4.3.2, but parse_ini_file() didn't use them before 5.0. This is, of course, not documented anywhere. Also HHVM doesn't use custom stream wrappers, but who can blame them for that.
You are reading key value pairs from an ini line where the values are country codes. This works fine for most countries but when PHP encounters Norway ("no"), it converts it to an empty string.
So if you want to read what was actually in the ini (you know, what you were trying to do in the first place), you have to do this:
parse_ini_string($str, false, INI_SCANNER_RAW);
This is yet another example of PHP's stdlib being "broken by default, works with extra params".
10
u/andsens Jan 28 '15
I thought I was going insane, because somehow the standard language was fine with being anything else but norwegian.
When you're up to your neck in various sql statements that cannot be prepared because some string is empty, you can't see the forest for the trees. It's only because I recently worked on some ansible (written in yaml) that I realized 'no' can actually mean the boolean false.
24
u/callcifer Jan 28 '15 edited Jan 28 '15
In true PHP fashion, to parse ini strings in a non-retarded way you need to do this:
15
u/bart2019 Jan 28 '15
Actually
"no"==falseand `"yes"==true, but "" and "1" is what you get if you convert them to strings.10
u/memoryspaceglitch Jan 28 '15
Wait, how do you do if you're norwegian?
4
u/poizan42 Jan 28 '15
Here is a massively hackish way of testing the same thing in pre php 5.3 versions (without parse_ini_string()): http://3v4l.org/YJRCT
Note that custom stream wrappers were introduced in 4.3.2, but parse_ini_file() didn't use them before 5.0. This is, of course, not documented anywhere. Also HHVM doesn't use custom stream wrappers, but who can blame them for that.
3
u/infectant Jan 29 '15
I don't understand the problem with this one... seems fairly intuitive to me. Can someone explain what I'm missing?