Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

PHP is awesome

Name: Anonymous 2007-08-28 17:56 ID:xY3vpdBA

This is how you create a anonymous function in PHP:

$newfunc = create_function('$a,$b', 'return "ln($a) + ln($b) = " . log($a * $b);');


Name: Anonymous 2007-08-30 15:35 ID:Heaven

>>39
No shit it was the same person. Fourchon is so slow I didn't think it took my first post. Perhaps it needs an EXPERT PROGRAMMER to rewrite it.

>It's not noticeably slow if you don't abuse it. Of course, you can't expect for ($i = 100000; --$i; lambda(...)); to work decently.

Why would you not expect a loop creating lambdas to work decently? I've done that in plenty of other languages. What's the excuse there?

>It's not noticeably slow if you don't abuse it. Of course, you can't expect for ($i = 100000; --$i; lambda(...)); to work decently.

create_function() just blindly calls eval on code passed into it. Oops!

Also, let's not forget the fact that Zend ignores optimizations on eval()ed code.

All of this adds up to one thing -- PHP's create_function and eval are horribly fucked... much like the language itself.

Name: Anonymous 2007-08-30 16:13 ID:kjnv7mW9

lambda functions unusable in create_function()

I made five distinct tests to bracket the issue:
TEST 1:
// Creating a function that calls an ordinary function (explict name)
function always_true(){return true;}
$afun = create_function('', 'return !always_true();');
echo "Calling $afun() " . ($afun() ? "returns true\n" : "returns
false\n");

TEST 2:
// Creating a function that calls an ordinary function (variable name)
function always_true(){return true;}
$b1 = 'always_true';
$bfun = create_function('','return !'.$b1.'();');
echo "Calling $bfun() " . ($bfun() ? "returns true\n" : "returns
false\n");

TEST 3:
// Creating a function that calls an anonymous function (explicit
name);
$c1 = create_function('','return true;');
$cfun = create_function('','return !'.chr(0).'lambda_3();');
echo "Calling $cfun() " . ($cfun() ? "returns true\n" : "returns
false\n");

TEST 4:
// Creating a function that calls an anonymous function (variable name)
$d1 = create_function('','return true;');
$dfun = create_function('','return !'.$d1.'();');
echo "Calling $dfun() " . ($dfun() ? "returns true\n" : "returns
false\n");

TEST 5:
// Using is_callable to get a callable version of anonymous function
name
$e1 = create_function('', 'return true;');
if(!is_callable($e1,false,$callable_e1)) die("Couldn't call anonymous
function.");
echo "Using $callable_e1 as name of anonymous function\n";
$efun = create_function('','return !'.$callable_e1.'();');
echo "Calling $efun() " . ($efun() ? "returns true\n" : "returns
false\n");

Expected result:
----------------
TEST 1:
Calling  lambda_1() returns false

TEST 2:
Calling  lambda_1() returns false

TEST 3:
Calling  lambda_2() returns false

TEST 4:
Calling  lambda_2() returns false

TEST 5:
Using  lambda_1 as name of anonymous function  [?]
Calling  lambda_2() returns false

Actual result:
--------------
Actual Results:
TEST 1:
Calling  lambda_1() returns false

TEST 2:
Calling  lambda_1() returns false

TEST 3:
Parse error: parse error, unexpected '}' in test.php : runtime-created
function on line 1
Fatal error: Function name must be a string in test.php on line 4

TEST 4:
Parse error: parse error, unexpected '}' in test.php : runtime-created
function on line 1
Fatal error: Function name must be a string in test.php on line 4

TEST 5:
Using  as name of anonymous function
Parse error: parse error, unexpected ')' in test.php : runtime-created
function on line 1
Fatal error: Function name must be a string in test.php on line 6

Name: Anonymous 2007-08-30 17:48 ID:Xqzm1rko

>>40-41
Because PHP does not have true anonymous or first-class functions you fuckface! Of course JavaScript can do it, but JavaScript is conceptually better than PHP in a lot of ways and does actually support functional programming. There's no excuse other than sucking. I'm not defending PHP, I'm just posting what I do to make my life better doing PHP. (At least I can pretend I'm doing something that resembles FP, have dynamic typing and built-in lists and dictionaries; it would be much, much worse with Java.)

create_function() just blindly calls eval on code passed into it. Oops!
So? You're not going to do create_function('$x', $_REQUEST['lol']), are you? You know what create_function is for, don't do anything crazy. Also, eval is SNAFU, but for other reason (that return insanity).

>>42
Yes, that's why you do what I said in >>16 to at least support it. I found that by accident as I was doing exactly that, so I cursed the guys who did PHP, and worked around it.

Name: Anonymous 2007-08-30 19:07 ID:Heaven

>>43
So, why the fuck should we use bad hacks with create_function? It's a horrible chunk of sludge. FP and PHP do not mix. GB2LISP. (actually love Lisp myself)

And no shit you aren't going to create_function('$foo', '$foo'); but what happens when you fuck up and use double quotes and end up with variable substitution you don't want (at all). What happens if the input is (gulp) generated or taken from a DB (seen it, what the fuck...)?

You really want to open up a dynamic entry point directly into the parser? In PHP?!?!?

Maybe in a language that wasn't already insecure, sure. But jesus... PHP?

Name: Anonymous 2010-04-21 9:36

Thread.bump('1188338059');

Name: Anonymous 2010-04-21 14:40

>>45
Yeah, thanks, I really needed to hate PHP even more. Fuck even Python has less fucked up lambdas, and those are obviously implemented precisely in a manner to punish the people who want them.

Name: Anonymous 2010-04-21 15:09

>>46
They've done it somewhat correctly now.
$f = function ($x) {return $x*2;}
echo $f(5); // 10

Name: Anonymous 2010-04-21 15:20

Yeah, this has long since changed with 5.3.

Say what you want about PHP, but at least it's never stagnant. It may never be the fastest or the most elegant, but it will always be an adequate tool for the job, for as long as server-side interpreted languages make sense on the web.

Name: Anonymous 2010-04-21 15:20

Yeah, this has long since changed with 5.3.

Say what you want about PHP, but at least it's never stagnant. It may never be the fastest or the most elegant, but it will always be an adequate tool for the job, for as long as server-side interpreted languages make sense on the web.

Name: Anonymous 2010-04-21 15:22

ignorePost(">>49");

Name: Anonymous 2010-04-21 15:33

>>48
Wow, as if my objections to PHP have anything to do with speed or even elegance.

it will always be [...] adequate
No, this is my objection. In no sense is PHP adequate. The worst part of the whole mess is that it is invariably written by people who think it is adequate. And then they go and plug the resulting foetid mess into a relational database most of the time. Gross!

Name: Anonymous 2010-04-21 16:35

>>51
foetid
I didn't know /prog/ was this literate.

Name: Anonymous 2010-04-21 16:38

>>52
The word you're looking for is ``British''.

Name: Anonymous 2010-04-21 16:41

>>53
I didn't know British waswere this literate.

Name: Anonymous 2010-04-21 16:44

>>53
I'm not British, ``faggot''-quoter.

Name: Anonymous 2010-04-21 16:54

>>55
Then quit spelling like one.

Name: Anonymous 2010-04-21 17:14

>>56
I have bad news for you. My American English spell check gave me the go-ahead on that one. If you weren't literally a child you might remember that has been the preferred spelling on this side of the pond until perhaps recently. And no, I will not quit being old. At least not until Dennis Ritchie dies.

Name: Anonymous 2010-04-21 17:22

>>57
You've misconfigured your spelling checker. The American spelling is, and always has been, fetid, whereas the spelling you used, foetid, is British. You can tell because the British managed not to mangle the Latin the word is derived from.
Since you seem to be quite bad at technology, perhaps you should find a paper dictionary to confirm this for you if you do not believe me.

Name: Anonymous 2010-04-21 17:24

>>51
PHP is certainly adequate. It is a good solution for small web projects on shared hosting. It was built to interface with relational databases from its earliest versions, and it's not difficult to understand why. So far you've yet to indicate any reason behind your objections.

Name: Anonymous 2010-04-21 17:36

>>59
Given its wonderful track record on security (which in the offcial implementation is mainly a consequence of every single contributor being a brain-damaged moron, though its duplication in its imitators shows that much of it is owing to the dreadful mess of a language that it is as well), any project on shared hosting is precisely what it's worst for.

Name: Anonymous 2010-04-21 17:39

>>58
My spell checker is fine, but do go back to your hooked on fonics. I am not sure which dictionary you'd expect me to check -- any that publish only misspellings is certainly incorrect and, I would, hope unrepresentative (I happen to know, in this case from experience.) Perhaps if you'd read more you'd have found literate Americans using the old form. Are they wrong to do this because they're American or are they merely discounted for being literate?

>>59
So far you've yet to indicate any reason behind your objections.
Oh you wanted real, defensible reasons? I don't care to argue it, but if you want examples there are a ton of them at http://php.net/ -- not to mention reams of data supporting the notion that PHP programmers are the worst kind.

Name: Anonymous 2010-04-21 18:07

>>58
Did you mean: fœtid?

Name: Anonymous 2010-04-21 19:07

>>61
literate Americans
Lol.

Name: Anonymous 2010-04-21 19:36

>>63
Now that you've made your choice, go to /b/ and post one of them cutesy images about how fat and/or ugly your girlfriend is. Oh wait.

Name: Anonymous 2010-04-21 20:58

>>61
It's well-known that literate Americans use British spelling, because everything worth reading was written by Englishmen. That doesn't have any bearing on what the correct spelling in American is.

Name: Anonymous 2010-04-21 22:01

>>65
I can't help but noticing >>63 said the same thing, but more succinctly.

Name: Anonymous 2010-04-21 23:08

>>65
Indeed, my good sir.

American here, by the way

Name: sage 2010-04-23 22:38

HEY LOGAN, I'MA EXPERT BBCODE PROGRAMMER.

Name: sage 2010-04-23 22:39

[b][i][o]HEY [u]LOGAN[/o], I'MA EXPERT[/u] BBCODE PROGRAMMER.[/i][/b]

Name: Anonymous 2010-04-23 22:40

HEY LOGAN, I'MA EXPERT BBCODE PROGRAMMER.

Name: Anonymous 2010-04-23 22:41

HEY LOGAN, I'MA EXPERT BBCODE PROGRAMMER.

Name: Anonymous 2010-04-23 22:42

HEY LOGAN, I'MA EXPERT BBCODE PROGRAMMER.

Name: Anonymous 2010-04-23 22:43

HEY LOGAN, I'MA EXPERT BBCODE PROGRAMMER.

Name: Anonymous 2010-04-23 22:46

HEY LOGAN, I'MA EXPERT BBCODE /PROG/RAMMER.

Name: Anonymous 2010-04-23 22:46

HEY LOGAN, I'MA EXPERT BBCODE /PROG/RAMMER.

Name: Anonymous 2011-02-04 11:22

Name: Anonymous 2011-02-04 14:45


Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List