473,320 Members | 2,020 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

can I use create_function to create enclosures?

Just noticed this for the first time:

http://us2.php.net/manual/en/functio...e-function.php

Anyone know if PHP supports enclosures, like Javascript or Ruby? I've
always assumed PHP lacked these. If I create a function with object
instances, will the instances retain their state if the function
definition is stored in a variable?

Apr 16 '07 #1
8 1826
lawrence k wrote:
Just noticed this for the first time:

http://us2.php.net/manual/en/functio...e-function.php

Anyone know if PHP supports enclosures, like Javascript or Ruby? I've
always assumed PHP lacked these. If I create a function with object
instances, will the instances retain their state if the function
definition is stored in a variable?
PHP runs server side. It has no idea what client-side languages such as
Javascript are.

PHP outputs HTML - and can output client side code such as Javascript,
but to PHP it's just text being output.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Apr 16 '07 #2
On Apr 16, 7:29 am, Jerry Stuckle <jstuck...@attglobal.netwrote:
lawrence k wrote:
Just noticed this for the first time:
http://us2.php.net/manual/en/functio...e-function.php
Anyone know if PHP supports enclosures, like Javascript or Ruby? I've
always assumed PHP lacked these. If I create a function with object
instances, will the instances retain their state if the function
definition is stored in a variable?

PHP runs server side. It has no idea what client-side languages such as
Javascript are.

PHP outputs HTML - and can output client side code such as Javascript,
but to PHP it's just text being output.
You misunderstood the question. I was asking "Does PHP support
closures?" That was the question. I like using closures in languages
such as Ruby and Javascript. I was wondering if there was any way to
do so in PHP. I'm assuming the answer is no.
Apr 16 '07 #3
lawrence k wrote:
On Apr 16, 7:29 am, Jerry Stuckle <jstuck...@attglobal.netwrote:
>lawrence k wrote:
>>Just noticed this for the first time:
http://us2.php.net/manual/en/functio...e-function.php
Anyone know if PHP supports enclosures, like Javascript or Ruby? I've
always assumed PHP lacked these. If I create a function with object
instances, will the instances retain their state if the function
definition is stored in a variable?
PHP runs server side. It has no idea what client-side languages such as
Javascript are.

PHP outputs HTML - and can output client side code such as Javascript,
but to PHP it's just text being output.

You misunderstood the question. I was asking "Does PHP support
closures?" That was the question. I like using closures in languages
such as Ruby and Javascript. I was wondering if there was any way to
do so in PHP. I'm assuming the answer is no.

OK, I understand now.

If you're talking about $this->value being used to define $value as a
class member, no.

You can do it for array elements, though -

$myArray['value'] = 123;

defines the array element with key 'value'.

Personally I've never liked being able to define variables dynamically.
It becomes very difficult to debug and/or modify the code.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Apr 16 '07 #4
On 15 Apr 2007 22:14:12 -0700, "lawrence k" <lk******@geocities.comwrote:
>Just noticed this for the first time:

http://us2.php.net/manual/en/functio...e-function.php

Anyone know if PHP supports enclosures, like Javascript or Ruby? I've
always assumed PHP lacked these. If I create a function with object
instances, will the instances retain their state if the function
definition is stored in a variable?
No, PHP doesn't support closures; create_function is basically just a
restricted eval(). The function definition is a string, and isn't connected to
the scope from which create_function is called.
--
Andy Hassall :: an**@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Apr 16 '07 #5
Anyone know if PHP supports enclosures, like Javascript or Ruby? I've
always assumed PHP lacked these. If I create a function with object
instances, will the instances retain their state if the function
definition is stored in a variable?
In the object oriented sense, yes. You can pass a function even if it is
a method of an instance. These functions are used in sorting, for
example (usort function). I never used pure lambda functions as I once
did in lisp, because I mainly write object-oriented code now.

See also the callback type in the documentation:
http://nl3.php.net/callback

Best regards,
--
Willem Bogaerts

Application smith
Kratz B.V.
http://www.kratz.nl/
Apr 17 '07 #6
On 16.04.2007 18:47 lawrence k wrote:
>
You misunderstood the question. I was asking "Does PHP support
closures?" That was the question. I like using closures in languages
such as Ruby and Javascript. I was wondering if there was any way to
do so in PHP. I'm assuming the answer is no.

hi there

php doesn't support closures directly, because function declarations are
processed at compile time and create_function() deals only with strings.

However, with some hacking it's possible to emulate closures (or,
rather, partial application) using eval or create_function. See e.g.
http://www.tagarga.com/blok/on/061218
--
gosha bine

extended php parser ~ http://code.google.com/p/pihipi
blok ~ http://www.tagarga.com/blok
Apr 17 '07 #7
You misunderstood the question. I was asking "Does PHP support
closures?" That was the question. I like using closures in languages
such as Ruby and Javascript. I was wondering if there was any way to
do so in PHP. I'm assuming the answer is no.

OK, I understand now.

If you're talking about $this->value being used to define $value as a
class member, no.

You can do it for array elements, though -

$myArray['value'] = 123;

defines the array element with key 'value'.

Personally I've never liked being able to define variables dynamically.
It becomes very difficult to debug and/or modify the code.

Closures are the only way to create protected class variables in
Javascript. In Ruby they are essential for the use of blocks. I wish
PHP supported them so I could add methods to the classes that my co-
worker wrote, without having to use inheritance or to open and edit
their source code.

Apr 24 '07 #8
On Apr 17, 3:39 am, Willem Bogaerts
<w.bogae...@kratz.maardanzonderditstuk.nlwrote:
Anyone know if PHP supports enclosures, like Javascript or Ruby? I've
always assumed PHP lacked these. If I create a function with object
instances, will the instances retain their state if the function
definition is stored in a variable?

In the object oriented sense, yes. You can pass a function even if it is
a method of an instance. These functions are used in sorting, for
example (usort function). I never used pure lambda functions as I once
did in lisp, because I mainly write object-oriented code now.
I don't know Lisp, but from your response, I'll assume that functions
are not first class objects in Lisp.

Apr 24 '07 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: TheKeith | last post by:
Hi, I'm just learning php now for the first time and I'm having a little trouble understanding something. In the following example: ...
1
by: Colin McKinnon | last post by:
Hi all, The thing I'm doing just now uses create_function(). This works fine provided I don't do something silly in the code I am trying to incorporate. Is there any way I can check the syntax...
3
by: Ian.H | last post by:
Hi all, I'm trying to write a PHP colour parser and after various attempts, something, somewhere trips it over. Some details: String to parse: $origString = '^1foo^5bar';
1
by: Patrick Flaherty | last post by:
Hi, I'm a programmer but haven't delved much into this part of Web-related stuff. How would I search for RSS feeds that have enclosures of type 'audio/mpeg'? Google, perl - I'm willing (and...
7
by: dog | last post by:
I've seen plenty of articles on this topic but none of them have been able to solve my problem. I am working with an Access 97 database on an NT4.0 machine, which has many Access reports. I...
4
by: I_AM_DON_AND_YOU? | last post by:
There is one more problem I am facing but didn't get the solution. In my Setup Program I am not been able to create 2 things (when the program is intalled on the client machine ) : (1) create...
10
by: Zack Sessions | last post by:
Has anyone tried to create a SQL7 view using the CREATE VIEW command and ADO.NET? If so, is there a trick in trapping a SQL error when trying to create the view? I have a VB.NET app that, amoung...
37
by: Steven Bethard | last post by:
The PEP below should be mostly self explanatory. I'll try to keep the most updated versions available at: http://ucsu.colorado.edu/~bethard/py/pep_create_statement.txt...
18
by: Steven Bethard | last post by:
I've updated the PEP based on a number of comments on comp.lang.python. The most updated versions are still at: http://ucsu.colorado.edu/~bethard/py/pep_create_statement.txt...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.