php-general Digest 23 May 2005 07:57:29 -0000 Issue 3470
Topics (messages 215714 through 215719):
Re: __get() not reentrant?
215714 by: Christopher J. Bottaro
215716 by: Marek Kilimajer
215717 by: Christopher J. Bottaro
financial application form
215715 by: Dave Sayer
Re: Search problem
215718 by: Joe Wollard
session handling
215719 by: eswar
Administrivia:
To subscribe to the digest, e-mail:
[EMAIL PROTECTED]
To unsubscribe from the digest, e-mail:
[EMAIL PROTECTED]
To post to the list, e-mail:
[email protected]
----------------------------------------------------------------------
--- Begin Message ---
Jochem Maas wrote:
> Christopher J. Bottaro wrote:
>> Maybe I'm using "reentrant" incorrectly, but here is what I mean...
>>
>> class Test {
>> function __get($nm) {
>> if ($nm == 'x')
>> return $this->func();
>> elseif ($nm == 'y')
>> return 'y';
>> elseif ($nm == 'xx')
>> return 'x';
>> }
>> function func() {
>> return $this->xx;
>> }
>> }
>> $t = new Test();
>> print $t->y . "\n";
>> print $t->xx . "\n";
>> print $t->x . "\n";
>> print $t->func() . "\n";
>>
>> I would expect the following code to output:
>> y
>> x
>> x
>> x
>>
>> But instead, it outputs:
>> y
>> x
>>
>> x
>>
>> Is this a bug? This limitation is not documented (maybe it should be?).
>
> its not a bug, I believe its documented somewhere how this works.
> bottom line __get() does not work from 'inside' the class/object,
> so do something like instead:
>
> function func() {
> return $this->__get('xx');
> }
>
> which may not please the soul, but does work ;-)
Hehe, my soul is hard to please...=P
Actually, __get() does work from inside the class. In the sample code I
posted, func() does indeed return 'x' when called from main. It does not
work when called from within a call to __get(). In other words,
$this->attribute does not work if __get() appears anywhere in the call
stack.
Its just a small annoyance. I use $this->attribute everywhere in the class,
but I have to remember to use $this->__get(attribute) in methods that can
be called from __get().
-- C
--- End Message ---
--- Begin Message ---
Christopher J. Bottaro wrote:
Jochem Maas wrote:
Christopher J. Bottaro wrote:
Maybe I'm using "reentrant" incorrectly, but here is what I mean...
class Test {
function __get($nm) {
if ($nm == 'x')
return $this->func();
elseif ($nm == 'y')
return 'y';
elseif ($nm == 'xx')
return 'x';
}
function func() {
return $this->xx;
}
}
$t = new Test();
print $t->y . "\n";
print $t->xx . "\n";
print $t->x . "\n";
print $t->func() . "\n";
I would expect the following code to output:
y
x
x
x
But instead, it outputs:
y
x
x
Is this a bug? This limitation is not documented (maybe it should be?).
its not a bug, I believe its documented somewhere how this works.
bottom line __get() does not work from 'inside' the class/object,
so do something like instead:
function func() {
return $this->__get('xx');
}
which may not please the soul, but does work ;-)
Hehe, my soul is hard to please...=P
Actually, __get() does work from inside the class. In the sample code I
posted, func() does indeed return 'x' when called from main. It does not
work when called from within a call to __get(). In other words,
$this->attribute does not work if __get() appears anywhere in the call
stack.
Its just a small annoyance.
I think it would be more annoying if __get() would be recursively called
to infinity.
--- End Message ---
--- Begin Message ---
Marek Kilimajer wrote:
> Christopher J. Bottaro wrote:
>> Jochem Maas wrote:
>>
>>
>>>Christopher J. Bottaro wrote:
>>>
>>>>Maybe I'm using "reentrant" incorrectly, but here is what I mean...
>>>>
>>>>class Test {
>>>> function __get($nm) {
>>>> if ($nm == 'x')
>>>> return $this->func();
>>>> elseif ($nm == 'y')
>>>> return 'y';
>>>> elseif ($nm == 'xx')
>>>> return 'x';
>>>> }
>>>> function func() {
>>>> return $this->xx;
>>>> }
>>>>}
>>>>$t = new Test();
>>>>print $t->y . "\n";
>>>>print $t->xx . "\n";
>>>>print $t->x . "\n";
>>>>print $t->func() . "\n";
>>>>
>>>>I would expect the following code to output:
>>>>y
>>>>x
>>>>x
>>>>x
>>>>
>>>>But instead, it outputs:
>>>>y
>>>>x
>>>>
>>>>x
>>>>
>>>>Is this a bug? This limitation is not documented (maybe it should be?).
>>>
>>>its not a bug, I believe its documented somewhere how this works.
>>>bottom line __get() does not work from 'inside' the class/object,
>>>so do something like instead:
>>>
>>> function func() {
>>> return $this->__get('xx');
>>> }
>>>
>>>which may not please the soul, but does work ;-)
>>
>>
>> Hehe, my soul is hard to please...=P
>>
>> Actually, __get() does work from inside the class. In the sample code I
>> posted, func() does indeed return 'x' when called from main. It does not
>> work when called from within a call to __get(). In other words,
>> $this->attribute does not work if __get() appears anywhere in the call
>> stack.
>>
>> Its just a small annoyance.
>
> I think it would be more annoying if __get() would be recursively called
> to infinity.
And what would make it any different from a normal recursive function?
Every recursive function runs the risk of going into infinite loop if the
programmer doesn't understand the basic concept (or makes a silly mistake).
Loops run the risk of going on indefinitely as well. Maybe PHP should
disable all forms of loops/recursion to protect the programmers from
themselves.
Trace my code for $t->x...
$t->x;
$t->__get('x');
$t->func();
$t->xx;
$t->__get('xx');
'x'
What is wrong with that? Why should PHP disallow that recursive __get()
call? It is perfectly valid recursive code. It terminates for all cases.
-- C
--- End Message ---
--- Begin Message ---
Hi, First post here.
I have a large application form (financial) which I have working fine but I
need to be able to have it either work as a single application or a joint
one. If joint it needs to display two forms for the user to fill in. I am
just wondering how I can do this without having to write a second form as
there are 8 pages (around a hundred fields) to this form and I don’t fancy
modifying all of the vars and fields to do this. If anyone knows how or can
point me in the right direction, id be most thankful.
Cheers
Dave
--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.322 / Virus Database: 266.11.15 - Release Date: 22/05/2005
--- End Message ---
--- Begin Message ---
I used to search the same way until someone on this list mentioned using
a fulltext index in mysql. Doing this almost eliminated all my headaches
with searching.
Easiest way to create a fulltext index is to use phpMyAdmin. Once you've
created the fulltext index on `title`,`description`,`price`,`weight` you
can then search all columns (much faster than the other way I might add)
by using a simply SQL query such as this:
$sql = "SELECT * FROM `products` WHERE
MATCH(`title`,`description`,`price`,`weight`) AGAINST ('" .
mysql_escape_string($_GET['query']) . "')";
More on FULLTEXT can be found here:
http://dev.mysql.com/doc/mysql/en/fulltext-search.html
Hope that helps!
-Joe W.
www.joewollard.com <http://www.joewollard.com>
[EMAIL PROTECTED] wrote:
Hi,
I need to build up a search module for a shop. If I make a basic search
(product title for example) it is ok.
$query = "SELECT product_id FROM products WHERE title LIKE '%$title%'";
But i need an advance search for more than one field (title, description,
price, weight)
The problem is that i don't know which field is filled in by the user (title,
description, price or weight)
I mean, the user can fill in all fields, or only price field, or title and
weight etc
How can i do the search?
Thanks
--- End Message ---
--- Begin Message ---
Dear sir
I am the php programmer. I am trying with session handling.It is not working
properly. sessions function well when I use browser on the machine where IIS is
installed. But through other machines, it always create two session file, one
is OK, the other is blank, nothing in it. the later is used by the session. So
all the thing I registered for the session can not be accessed later. need help
please help me in this situation.
with regards
Eswaramoorthy
[EMAIL PROTECTED]
--- End Message ---