php-general Digest 24 May 2011 13:52:11 -0000 Issue 7326
Topics (messages 313125 through 313129):
Re: best practise accessing object's attributes from objects itself
313125 by: David Harkness
Re: observer pattern
313126 by: Daevid Vincent
313127 by: Eric Butera
Re: strcmp()?
313128 by: Vitalii Demianets
WHERE field = a range of values (value
313129 by: Paul S
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 ---
On Mon, May 23, 2011 at 6:29 AM, Simon Hilz <[email protected]> wrote:
> i was wondering if there is any best practise known how one should access
> the attributes of an object from the object itself.
>
For most properties I use $this->property within the object because nine
times out of ten no work ever needs to be done with them. Usually they are
set by the constructor and optionally changed externally using a setter. As
long as only the class and subclasses access properties in this manner, it's
easy to change them to use an accessor later if necessary. I never access
the properties directly from unrelated classes.
When a property needs to have logic applied--either during get or set--I'll
use accessors even inside the class to ensure that work is done consistently
and avoid repetition. In some rare cases (testing framework) I use __get()
and __set() so subclasses can use $this->property but get redirected through
the accessor. This isn't possible inside the class, however, because the
magic functions are only invoked when the caller cannot directly access the
property.
David
--- End Message ---
--- Begin Message ---
> -----Original Message-----
> From: Eric Butera [mailto:[email protected]]
> Sent: Friday, May 20, 2011 2:25 PM
> To: PHP
> Subject: Re: [PHP] observer pattern
>
> [whoops didn't hit reply-all]
>
> On Wed, May 18, 2011 at 5:18 AM, Ken Guest <[email protected]> wrote:
> > Lo,
> >
> > so, I'm wondering - how many of you use the observer pattern in php;
> > and if so, do you implement it 'standalone' or with the spl classes?
> > Is there any particular advantage to doing it "your way"; whichever
> > your way is?
> >
> > Ken
> >
> > --
> > http://blogs.linux.ie/kenguest/
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
>
> I use it quite a bit over the various projects I maintain. It allows
> subjects to trigger events that observers can process if they're
> interested, or better yet, completely ignore. This allows
> standardized code bases to create nice hooks that allow extensibility
> without needing to place one-off code inside the main project.
>
> A quick example might be on saving a record in your code, it triggers
> an event, then an observer in a custom site watches for said event and
> injects/updates a search entry in Lucene. This way one site can have
> a custom search engine that another site might not need.
>
> I started off with the concepts I found in
> http://examples.stubbles.net/docroot/events/ but created my own
> because I wanted something stand-alone.
Well, you (or in this case, *I*) learn something new every day.
I had no idea PHP could do observers. How very "Java" (and neat!)
Granted, it is just a design pattern, but to have the SplObserver stuff built
in is pretty cool.
What version of PHP is this available from? The web page doesn't say.
http://www.labelmedia.co.uk/blog/posts/php-design-patterns-observer-pattern.html
http://cormacscode.wordpress.com/2010/10/12/practical-example-php-implementation-of-the-observer-pattern/
http://www.php.net/manual/en/book.spl.php
--- End Message ---
--- Begin Message ---
On Mon, May 23, 2011 at 5:14 PM, Daevid Vincent <[email protected]> wrote:
>> -----Original Message-----
>> From: Eric Butera [mailto:[email protected]]
>> Sent: Friday, May 20, 2011 2:25 PM
>> To: PHP
>> Subject: Re: [PHP] observer pattern
>>
>> [whoops didn't hit reply-all]
>>
>> On Wed, May 18, 2011 at 5:18 AM, Ken Guest <[email protected]> wrote:
>> > Lo,
>> >
>> > so, I'm wondering - how many of you use the observer pattern in php;
>> > and if so, do you implement it 'standalone' or with the spl classes?
>> > Is there any particular advantage to doing it "your way"; whichever
>> > your way is?
>> >
>> > Ken
>> >
>> > --
>> > http://blogs.linux.ie/kenguest/
>> >
>> > --
>> > PHP General Mailing List (http://www.php.net/)
>> > To unsubscribe, visit: http://www.php.net/unsub.php
>> >
>> >
>>
>> I use it quite a bit over the various projects I maintain. It allows
>> subjects to trigger events that observers can process if they're
>> interested, or better yet, completely ignore. This allows
>> standardized code bases to create nice hooks that allow extensibility
>> without needing to place one-off code inside the main project.
>>
>> A quick example might be on saving a record in your code, it triggers
>> an event, then an observer in a custom site watches for said event and
>> injects/updates a search entry in Lucene. This way one site can have
>> a custom search engine that another site might not need.
>>
>> I started off with the concepts I found in
>> http://examples.stubbles.net/docroot/events/ but created my own
>> because I wanted something stand-alone.
>
> Well, you (or in this case, *I*) learn something new every day.
>
> I had no idea PHP could do observers. How very "Java" (and neat!)
> Granted, it is just a design pattern, but to have the SplObserver stuff built
> in is pretty cool.
> What version of PHP is this available from? The web page doesn't say.
>
> http://www.labelmedia.co.uk/blog/posts/php-design-patterns-observer-pattern.html
> http://cormacscode.wordpress.com/2010/10/12/practical-example-php-implementation-of-the-observer-pattern/
> http://www.php.net/manual/en/book.spl.php
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
Hi Daevid,
According to http://us3.php.net/manual/en/splobserver.update.php, (PHP
5 >= 5.1.0)
--- End Message ---
--- Begin Message ---
On Monday 23 May 2011 15:00:27 tedd wrote:
> >Are you absolutely certain about that?
> >
> > echo strcmp('These are nearly equal', 'These are almost equal'), "\n";
> > echo strcmp('different', 'unequal'), "\n";
> > echo strcmp('b', 'a'), "<br />\n";
My result is:
13 -17 1
I'm runninng PHP 5.2.14 on the ARM Linux with uClibc.
Certainly the result depends on architecture and/or libc, because PHP just
calls system strcmp, nothing more.
So. to write compatible scripts one should check "< 0", not "== -1".
--
With Best Regards,
Vitalii Demianets
Head engineer
Factor-SPE
Kiev, Ukraine
tel/fax: +380(44)249-21-63
--- End Message ---
--- Begin Message ---
I'd like to check a table to retrieve rows for which one field equals one
of a set of values
....
#get products(fields) in category list
while ($row = $db_connect->fetch_array($productsincategory_list)) {
$product = $row ['selection'];
$fields = "$fields" . " $product,";
}
$fields = substr($fields,'',-1);
###### echo "$fields<br><br>";
###### $fields = Prod1, ProD2, Prod3
This ...
$db_connect->fetch_array($sql_result);
$store_result = $db_connect->query("select * from $sql_usertable WHERE
(($sql_usertable.product1 = '($fields)')||( $sql_usertable.product2 =
'($fields)')||($sql_usertable.product3 = '($fields)')) order by id desc
limit $entry, $entries_per_page");
doesn't work. It selects nothing (obviously because no single field equals
' (Prod1, Prod2, Prod3) '). But it's the idea. Can I change the:
= '($fields)'
syntax I'm trying?
The actual select checks more fields for this or that and gets more
complicated so I'd like to keep this as simple
as possible. I would like to do this without UNIONS (in one pass) if
possible (my
dbsql.php doesn't seem to go beyond regular query).
--
Using Opera's revolutionary email client: http://www.opera.com/mail/
--- End Message ---