Page 1 of 1

obviously missing php functions

Posted: Thu Mar 03, 2005 12:22 pm
by djot
-
Hi,

Sometimes I really wonder why some simple functions are available only for one situtation and not for the second obvious one.

Example 1:
$output .= $more; // possible
$output =. $head; //not possible

Example 2:
strstr
//Returns part of haystack string from the first occurrence of needle to the end of haystack. Great! But I most times need the first part.

djot
-

Posted: Thu Mar 03, 2005 12:39 pm
by feyd
I don't see a point in such a function. If you want the part of a string leading to a substring.. use strpos() and substr()

Re: obviously missing php functions

Posted: Thu Mar 03, 2005 12:58 pm
by smpdawg
djot wrote:-
$output =. $head; //not possible
-
What language do you use that would allow that construct?

As it is unary operations can be confusing to people that are only vaguely familiar with them. If you add some variation that is very similar to an existing operator you will risk situations where people think they are doing one thing and yet they are getting an "unexpected" result. Obviously this would not happen to people that are quite familiar with PHP's syntax but why muddy the waters.

Besides, how hard is it to type this?

Code: Select all

$output = $head . $output;
This is obvious to all but the casual programmer.

PHP already has unary operators that behave in a manner that is inconsistent with conventional wisdom, adding more would be troublesome.

As for the second example. Why clutter up PHP with a bunch of special case functions that may be rarely used? There any many functions that I use and have written that are good for me but does that mean I should try to roll them into PHP for everyone to use?

Lastly. I am not really sure that this topic belongs in the forum. It would seem that it would be a better candidate for Theory & Design or Miscellaneous but what do I know?

BTW - Don't take my comments personally, they are just my opinions.

Posted: Thu Mar 03, 2005 1:06 pm
by djot
-
Hi,

I didn't want to get workarounds...
strpos() and substr()
Yes sure, not too hard. But why should I use it if it would be able in one single function. strpos is also invoked, and depending of what you want some more string functions. And that's not very handy.
$output = $head . $output;
That is not an explanation why $output =. $head; should not be possible. Why is .= possible?
BTW - Don't take my comments personally, they are just my opinions.
Sure not :) But it seems noone understands my point of view.

djot
-

Posted: Thu Mar 03, 2005 1:17 pm
by smpdawg
No language will ever or can ever have every function that we all would like it to have. Instead it has to be a compromise that is made up of largely useful functions and functions that simplify horrific tasks. In a situation when you are reducing two function calls to one it is better to leave it out of the language and just write a function at keep it in some common functions library.

So that may not seem like an answer but if I have 50 functions that I think are necessary and you have 50 more and every other PHP programmer wants more, how big would PHP become? You have to look at functions and say "Will the super-majority of PHP programmers use it?" If the answer is no, it needs to be left out. BTW - Super-majority in the political sense - 2/3, 3/4 but more than 50/50.

So why does .= exist? Simple. PHP is written in C. The PHP unary operators and similar in nature and functionality to the unary operators in C. So if it doesn't exist in C, it is not likely to exist in PHP and that is largely a matter of preference for the developers of the language.

Unary operators are terribly handy but in PHP there is a notable example of a unary not behaving like C and that makes me hate them in PHP.

Posted: Thu Mar 03, 2005 1:19 pm
by feyd
what workaround? You'd have to do the same exact thing in this "function" you want.. :?

make it a function of your own.. in your own library. This is the first time I have ever heard of someone wanting a function that returns the leading string to a substring.

And the very likely reason why =. doesn't exist is because that's not how assignment operators are set up.

I've never needed such a function.. I rarely need to prepend data to a string. Barely enough to even be lazy about making a reassignment work..

:?