php-general Digest 24 Jun 2005 14:06:20 -0000 Issue 3530
Topics (messages 217528 through 217541):
Re: Strange notation to create object
217528 by: Matthew Weier O'Phinney
217529 by: Robert Cummings
217530 by: Evert | Rooftop Solutions
217536 by: vieonet forums
217540 by: Michael
217541 by: Jason Barnett
Re: Socket server in PHP
217531 by: Richard Lynch
217535 by: vieonet forums
Re: Help with image map problem...
217532 by: Richard Lynch
Re: Extra (persistant) tier
217533 by: Richard Lynch
Re: fopen problem
217534 by: Richard Lynch
Re: comparing two texts
217537 by: Rory Browne
Re: Re-inserting newlines
217538 by: Jochem Maas
Re: Help recognizing bots?
217539 by: Dotan Cohen
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 ---
* Jason Barnett <[EMAIL PROTECTED]> :
> Matthew Weier O'Phinney wrote:
> ...
> > This doesn't demonstrate what the OP was talking about, which is initial
> > assignment of an object using a reference operator. The results of this
> > make perfect sense to me -- the references are passed exactly as I would
> > expect.
>
> But not exactly as I would expect! I thought that all objects were
> created as references, but apparently this is not the case.
Here's what happens (in PHP5) with the statement '$obj = new Class();':
* the 'new Class()' construct creates an object
* it then returns a reference to the object
* assignment is then to the reference
Thus, $obj is actually a *pointer* to the object -- not the actual
object.
> Is there some kind of dereferencing going on when you're using an
> object on the right side of the assignment (=) operator?
No. It's simpler: you're simply passing around a reference to the
object.
Before, in PHP4, when you would use assignment, the variable on the left
side would receive a *copy* of the object on the right -- a clone of the
object. *UNLESS* what you had on the right side was a reference; then it
would clone the reference, meaning you have the same behaviour as in
PHP5.
This is why the $obj =& new Class() idiom occurred in PHP4; that way you
could pass around your object safely, because you were simply passing
around a reference to an object. PHP5 simplifies this by simply
assigning the object reference only in the first place.
--
Matthew Weier O'Phinney | WEBSITES:
Webmaster and IT Specialist | http://www.garden.org
National Gardening Association | http://www.kidsgardening.com
802-863-5251 x156 | http://nationalgardenmonth.org
mailto:[EMAIL PROTECTED] | http://vermontbotanical.org
--- End Message ---
--- Begin Message ---
On Thu, 2005-06-23 at 21:44, Matthew Weier O'Phinney wrote:
> * Jason Barnett <[EMAIL PROTECTED]> :
> > Matthew Weier O'Phinney wrote:
> > ...
> > > This doesn't demonstrate what the OP was talking about, which is initial
> > > assignment of an object using a reference operator. The results of this
> > > make perfect sense to me -- the references are passed exactly as I would
> > > expect.
> >
> > But not exactly as I would expect! I thought that all objects were
> > created as references, but apparently this is not the case.
There's a difference between a reference to a reference and a copy of a
reference *hehehe*.
Cheers,
Rob.
--
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting |
| a powerful, scalable system for accessing system services |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for |
| creating re-usable components quickly and easily. |
`------------------------------------------------------------'
--- End Message ---
--- Begin Message ---
Robert Cummings wrote:
On Thu, 2005-06-23 at 13:36, Matthew Weier O'Phinney wrote:
* Robert Cummings <[EMAIL PROTECTED]> :
On Thu, 2005-06-23 at 11:32, Matthew Weier O'Phinney wrote:
The above notation is unnecessary when developing in PHP5, as objects in
PHP5 are passed by reference by default. However, in PHP4, this was
Not entirely, there's still a subtle difference in PHP5 between
assigning an object with = versus assigning with = &.
Would you mind explaining the difference? I've seen nothing in the docs,
to indicate that assigning objects with =& in PHP5 is necessary, or even
desired. My experience with PHP5 hasn't shown this either. I'd be
interested to know to what you refer.
See for yourself when running the following script:
Cheers,
Rob.
I am stunned! Since I try to make my code working for both PHP4 and PHP5
I try to never rely on PHP4's standard cloning behaviour, and use &
where I can, so I have never really encountered this, but this will
propably save my a lot of frustration when the rest of the world says
goodbye to PHP4. (I remember when I first encountered the 'references in
constructor'-issue)
excellent stuff!
grt,
Evert
--- End Message ---
--- Begin Message ---
In php5 any object is moving as reference. you need special declaration, if
you want to duplicate(copy/clone) an object.
regards
david
----- Original Message -----
From: "Robert Cummings" <[EMAIL PROTECTED]>
To: "Matthew Weier O'Phinney" <[EMAIL PROTECTED]>
Cc: "PHP-General" <[email protected]>
Sent: Thursday, June 23, 2005 11:50 PM
Subject: Re: [PHP] Re: Strange notation to create object
On Thu, 2005-06-23 at 15:28, Matthew Weier O'Phinney wrote:
* Robert Cummings <[EMAIL PROTECTED]> :
> On Thu, 2005-06-23 at 13:36, Matthew Weier O'Phinney wrote:
> > * Robert Cummings <[EMAIL PROTECTED]> :
> > > On Thu, 2005-06-23 at 11:32, Matthew Weier O'Phinney wrote:
> > > > The above notation is unnecessary when developing in PHP5, as
> > > > objects in
> > > > PHP5 are passed by reference by default. However, in PHP4, this
> > > > was
> > >
> > > Not entirely, there's still a subtle difference in PHP5 between
> > > assigning an object with = versus assigning with = &.
> >
> > Would you mind explaining the difference? I've seen nothing in the
> > docs,
> > to indicate that assigning objects with =& in PHP5 is necessary, or
> > even
> > desired. My experience with PHP5 hasn't shown this either. I'd be
> > interested to know to what you refer.
>
> See for yourself when running the following script:
>
> <?php
>
> class a
> {
> }
>
> class b
> {
> }
>
> $aObj = new a();
> $bObj = new b();
>
> $foo1 = $aObj;
> $foo2 = $aObj;
> $foo3 = $foo1;
> $foo4 = &$foo2;
>
> echo "------------------\n";
> print_r( $foo1 );
> print_r( $foo2 );
> print_r( $foo3 );
> print_r( $foo4 );
>
> $foo1 = $bObj;
> $foo2 = $bObj;
>
> echo "------------------\n";
> print_r( $foo1 );
> print_r( $foo2 );
> print_r( $foo3 );
> print_r( $foo4 );
>
> $foo1 = &$aObj;
> ?>
This doesn't demonstrate what the OP was talking about, which is initial
assignment of an object using a reference operator. The results of this
make perfect sense to me -- the references are passed exactly as I would
expect.
Let me rephrase my question to you: is there a reason to do the initial
object assignment using a reference operator using PHP5? I.e., is there
a good reason to do this:
$foo =& new Foo();
instead of:
$foo = new Foo();
I haven't seen any reason to do the former case using PHP5.
Your original response said that the above notation was unneccessary, I
took that to mean the & operator for reference. Looking back I see ow
that your comment was ambiguous, and I agree there is no need for the &
when assigning a new object. I was merely clarifying that references and
normal assignment are not synonymous for objects in PHP 5.
Cheers,
Rob.
--
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting |
| a powerful, scalable system for accessing system services |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for |
| creating re-usable components quickly and easily. |
`------------------------------------------------------------'
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--- End Message ---
--- Begin Message ---
John Hinton wrote:
Michael Stepanov wrote:
With a return receipt attached....
and I'm wondering if we all return the receipt each time someone forgets
about this on various mailing lists, would the 6583 subscribers actually
returned the receipt, would it break the habit?
All in fun... sorry Michael.. it just happened to be yours that finally
convinced me to send this. I just get tired of the interruption of my
delete process.
Sorry for that. It's my working email and sometimes it's useful to see
did somebody read your email or not.
And many thanks, guys, for you explanation!
Best,
John Hinton
--
Best regards,
Michael Stepanov,
www.stepanoff.org
--- End Message ---
--- Begin Message ---
Robert Cummings wrote:
...
There's a difference between a reference to a reference and a copy of a
reference *hehehe*.
Cheers,
Rob.
Dear diary: jackpot!
Now that makes sense. And am I correctly filling in the blanks when I
guess that $foo3 = $aObj is merely copying the reference instead of
referencing the reference? I probably could have written that more
clearly, but I think you get what I'm saying.
--
NEW? | http://www.catb.org/~esr/faqs/smart-questions.html
STFA | http://marc.theaimsgroup.com/?l=php-general&w=2
STFM | http://php.net/manual/en/index.php
STFW | http://www.google.com/search?q=php
--- End Message ---
--- Begin Message ---
On Wed, June 22, 2005 11:52 pm, kioto said:
> Hi all sorry for the ignorance :D.This is my first time with Socket and
> i have
> a question for you.I want create a script that run like daemon in
> background
> and listen incoming request.It's possible with socket open a stream to a
> directory
> and check any change on this directory ?
> I want send notify about the state of directory through e-mail for
> example:
> when a user add new files or change any data.
Sort of.
I don't think you need anything as fancy as a Socket to do what you want.
Just:
http://php.net/filemtime on the directory to detect contents changed
http://php.net/opendir and readdir to see what's in it
http://php.net/clearstatcache to make PHP forget cached status of the above
http://php.net/mail to send whatever emails you want
An infinite loop with http://php.net/sleep to do this every few seconds.
You'd maybe want to use http://php.net/pcntl to respond to system signals...
You'd maybe want to store the current filemtime and "current" directory
contents in a database or file so you'd be able to start/stop your process
and still send every email for all changes, even the ones that happen
while your program wasn't running.
You could maybe launch it from the shell with "nohup" to NOT get killed,
as I sort of understand it... Better read "man nohup" I think...
Assuming it's RedHat or similar, you'd want to write a /etc/rc.d/init.d
shell script to start/stop the PHP script.
I dunno where you thought you'd want a Socket in all this. [shrug] Maybe
I'm missing something...
Or did you want to have it respond to requests for info about a specific
directory?
Perhaps what you REALLY want is another process that listens on a Socket
to register the email has an "interest" in a specific directory. But you
could do that in a web FORM just as easily. Then your program above would
run through all the email/directory combinations and do its thing in a
more granular manner.
--
Like Music?
http://l-i-e.com/artists.htm
--- End Message ---
--- Begin Message ---
Hi
I suggest to use cron table against php deamon, It'will we be more stable
and using less load.
regards
----- Original Message -----
From: "Richard Lynch" <[EMAIL PROTECTED]>
To: "kioto" <[EMAIL PROTECTED]>
Cc: "php-general" <[email protected]>
Sent: Friday, June 24, 2005 5:18 AM
Subject: Re: [PHP] Socket server in PHP
On Wed, June 22, 2005 11:52 pm, kioto said:
Hi all sorry for the ignorance :D.This is my first time with Socket and
i have
a question for you.I want create a script that run like daemon in
background
and listen incoming request.It's possible with socket open a stream to a
directory
and check any change on this directory ?
I want send notify about the state of directory through e-mail for
example:
when a user add new files or change any data.
Sort of.
I don't think you need anything as fancy as a Socket to do what you want.
Just:
http://php.net/filemtime on the directory to detect contents changed
http://php.net/opendir and readdir to see what's in it
http://php.net/clearstatcache to make PHP forget cached status of the
above
http://php.net/mail to send whatever emails you want
An infinite loop with http://php.net/sleep to do this every few seconds.
You'd maybe want to use http://php.net/pcntl to respond to system
signals...
You'd maybe want to store the current filemtime and "current" directory
contents in a database or file so you'd be able to start/stop your process
and still send every email for all changes, even the ones that happen
while your program wasn't running.
You could maybe launch it from the shell with "nohup" to NOT get killed,
as I sort of understand it... Better read "man nohup" I think...
Assuming it's RedHat or similar, you'd want to write a /etc/rc.d/init.d
shell script to start/stop the PHP script.
I dunno where you thought you'd want a Socket in all this. [shrug] Maybe
I'm missing something...
Or did you want to have it respond to requests for info about a specific
directory?
Perhaps what you REALLY want is another process that listens on a Socket
to register the email has an "interest" in a specific directory. But you
could do that in a web FORM just as easily. Then your program above would
run through all the email/directory combinations and do its thing in a
more granular manner.
--
Like Music?
http://l-i-e.com/artists.htm
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--- End Message ---
--- Begin Message ---
On Wed, June 22, 2005 10:16 pm, Joey said:
> If I put this in the .php file, the results are as expected:
> Value: <% echo $value; %>
>
> If in the SAME file I put:
> <map name="FPMap0">
> <area href="display_status.php?searchby=cust_no&search=1&value="<% echo
> $value %>" shape="rect" coords="51, 1, 215, 34">
> </map>
I'm gonna go out on a limb and put my money on:
Your <map> stuff is inside of a FUNCTION block, where $value is not defined.
You need to pass $value into your function.
Or you could declare it "global" in the function, but that's just icky.
--
Like Music?
http://l-i-e.com/artists.htm
--- End Message ---
--- Begin Message ---
On Wed, June 22, 2005 8:35 pm, Leila Lappin said:
> When I worked with other OO languages, I usually designed my persistent
> business objects in two levels. A level (lower level) designed and
> implemented direct database calls. Each database table had a class
> abstraction at this level which provided the database calls for saving,
> loading and etc. At this level I also provided for the caching
> considerations, i.e. if a table was already queried and a list was
> available
> the list in memory was used instead of querying again.
I had a guy hired me to do that once.
He had me budgeted for about a month to write all the classes.
I spent two days writing a PHP script to write a PHP class for each table
in the database, using mysql_* introspection functions instead. :-)
He was pretty happy, since I saved him about $10,000, give or take.
The project died long before he ever got to the point of having me do the
next level...
Which is just as well.
I REALLY don't understand why anybody would abstract out every single
table as a separate class like that.
Surely there are some COMMON features and behaviours between the fields of
any given MySQL type.
Wouldn't it make a LOT more sense to have a single abstract class that,
given a MySQL table-name, would provide an object cache of data structures
that matched the table field names/types?
Surely the "text" field in table "foo" isn't all that different from the
"text" field in table "bar" at that level.
Maybe that's just me being ornery.
> The next level was where the business model was implemented. If a
> business
> object required information from three tables that related to each other
> in
> a certain way the load methods would access the objects from cached lists
> in
> three different classes (each representing a database table) and created
> the
> final list. At this stage the list was cached and also represented the
> business logic.
Woof.
Now see, there, I gotta wonder is your cache really faster than a good
single query?
Cuz I'm thinking three separate queries for the data is gonna be a lot
more expensive. Sure, maybe it's cached. Or maybe it's not.
With the relatively SHORT life-time of a PHP script (you hope) the odds on
any given datum being cached should be pretty LOW, I would think.
Plus, the way this works out, you're probably going to end up having a
separate query for every row if you are displaying, say, 10 "rows" of
inter-related data from three tables.
That's 30 queries instead of 1.
That can't be faster than one well-written query.
> Although I haven't done this in PHP I think with PHP5 it's possible. The
> only challenge may be the caching of query results but I think Pear
> modules
> already have something about that.
Caching query results should be relatively easy...
Of course, your DATABASE server and your Operating System are *already*
caching data for you. Will your cache on top of their cache really provide
significant performance boost in PHP?
Plus, if you design the Application Logic correctly, you shouldn't *HAVE*
duplicate queries to get the same data in a single script.
This whole data-cache thing might make sense in a language where there is
a central shared cache (Java? JSP?) but in PHP I just don't see it being
"all that"
By the time you've filled up your cache with all the stuff you are going
to re-use, the script should be FINISHING.
PHP is not Java.
The solutions that are great in Java aren't in PHP sometimes. And vice
versa, of course.
Now if you combine this with some kind of PHP Application Framework, and
throw away the whole point of the cornerstone of the share-nothing
architecture (which has pros and cons) then you might maybe have a
significant performance increase... But there ain't such a beast yet, far
as I know, though some folks are working on them.
So, I gotta say, if you did this in PHP, you've made a fundamental error
in assessing the performance/benefit/cost ratios of what makes a PHP
Application fast.
This is all just MY OPINION.
I'm sure somebody is going to tell me just how stupid and naive I mussed
be for not undersanding OO.
Never mind I spent 15 years hacking in Common Lisp where damn near
*everything* is an object and some of my OO code is still in production
use 10 years after it was written.
Somebody's bound to post how the maintainability would be SOOO much better
it's worth the performance price. I disagree.
I believe there are BETTER abstraction models for how PHP works than the
"one class per db table".
--
Like Music?
http://l-i-e.com/artists.htm
--- End Message ---
--- Begin Message ---
On Thu, June 23, 2005 4:33 pm, Ross said:
> Warning: fopen(counterlog.txt) [function.fopen]: failed to open stream:
> Permission denied in c:\Inetpub\wwwroot\pillars\index.php on line 30
The PHP user does *NOT* have permission to open the counterlog.txt file.
Exactly *HOW* you change permissions changed in every Windoze version,
which suck, but there it is.
You should A) post *which* Windows OS you are using and B) try the Windows
list and C) poke around with Windows Explorer first to see if you can't
make the counterlog.txt file be owned by the User PHP is running as, which
you can find out from http://php.net/phpinfo
Actually, do ABC) in reverse order :-)
> Warning: fwrite(): supplied argument is not a valid stream resource in
> c:\Inetpub\wwwroot\pillars\index.php on line 33
>
> Warning: fclose(): supplied argument is not a valid stream resource in
> c:\Inetpub\wwwroot\pillars\index.php on line 36
These are a direct result of the first error.
Your script should NOT have even *TRIED* to run these functions, once it
failed to open the file in the first place.
Add a lot more error-checking to your script.
Once you "fix" the first error, these errors will "go away"
In Reality, they are just waiting to re-surface when something else goes
wrong with your file access.
So, actually, fix your script to skip these lines *FIRST* then fix the
error above. Consider it part of the learning to write Good Code.
--
Like Music?
http://l-i-e.com/artists.htm
--- End Message ---
--- Begin Message ---
Folks
There's no need to be quite so rude, when informing someone that you
don't know of any existing PHP code(diff isn't written in PHP), that
will fulfull their requirements.
Jenny:
Check out various PHP wikis. Most of them have a history feature, that
allows you to compare current with previous texts, which sounds pretty
much like what you're looking for.
Failing that check pecl for the xdiff extension.
www.php.net/manual/en/ref.xdiff.php
On 6/23/05, Richard Lynch <[EMAIL PROTECTED]> wrote:
> On Thu, June 23, 2005 5:25 am, Tom Rogers said:
> > Hi,
> >
> > Thursday, June 23, 2005, 9:42:34 PM, you wrote:
> > .
> > .
> > .
> >
> > JM> whereas I'll happily spend an hour writing up and contemplating
> > someone
> > JM> else's problem - I don't have five minutes for people who are
> > expecting to be
> > JM> spoonfed (go learn ASP and get a support contract, thanks ;-).
> >
> > Perhaps I missed it but could you point out the bit where the original
> > poster asked to be spoon fed??
>
> After she rejected using exec("diff") and then rejected a starter script
> to roll her own and then said "I guess it can't be done" ???
>
> Sounds like a request to have the pre-built PHP function already written
> to do exactly what she wanted to me.
>
> But maybe we're just being dense and not understanding what she wanted...
>
> I doubt it, though.
>
> I don't care, though. Today's newbie is tomorrow's Programmer. Some day
> she'll maybe write that script she deemed impossible today, and contribute
> it back to the community.
>
> Or maybe she'll some day add a PHP Module to interface directly to "diff"
> somehow.
>
> Or maybe somebody else will read this thread and be inspired to write one
> and contribute it.
>
> Maybe it will spawn a hundred different 'diff' classes in the future.
>
> Maybe it will die an ignomious death.
>
> You makes your posts and you takes your chances.
>
> [shrug]
>
> If you get all bent out of shape by everybody that comes down the pike and
> doesn't like that there isn't the phpBB equivalent of a "diff" feature
> "out there" (or whatever feature they want) then you're in the wrong
> place...
>
> Lots of people build perfectly fine websites with pre-assembled large
> bodies of code. More power to them.
>
> So they ask for Feature X and go away disappointed it's not there ready
> for them. Okay.
>
> Enough of them ask, one of them will build it.
>
> That's the beauty of OpenSource.
>
> If you get discouraged by the 1,000 that ask before the one that builds...
> Re-think your commitment to OpenSource.
>
> Enough philosophising.
>
> Time to code.
>
> --
> Like Music?
> http://l-i-e.com/artists.htm
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--- End Message ---
--- Begin Message ---
Philip Thompson wrote:
On Jun 23, 2005, at 4:13 PM, Richard Lynch wrote:
...
Well, that was a mouthful. I actually am using a Mac and it showed \r \n
I reckon you could edit together a nice fat 700 page book on PHP just by
scraping
posts made by Richard :-) ... every other month ;-)
to me. What I think I will do is not use mysql_real_escape_string until
I want to actually insert it into the database. So the information I
YES YES YES. good man, that is a good observation - i.e. you should only
be escaping/santizing/whatever data for the specific purpose you have in mind
and not blanket escaping regardless of the directions you will be throwing the
data in.
re-display back to the user *should* be the same as what they wrote.
actually I have DB edit screens that always show what is in the DB rather than
what the
user has tried to submit - because otherwise the user tends to think that their
changes
were accepted rather (and no ammount of errors/warning/whatever will change
their minds)
that the DB choked on their input - in such cases I just throw out everything
that could not
be updated - the user is garanteed to be looking at whatever the DB contains
when a
page/editform is loaded.
Thanks for your inputs. I appreciate each of you.
me too, but I'm biased towards Paris Hilton ;-)
~Philip
--- End Message ---
--- Begin Message ---
On 6/24/05, Richard Lynch <[EMAIL PROTECTED]> wrote:
> On Thu, June 23, 2005 3:37 am, JamesBenson said:
> > http://www.funender.com/phpBB2/about18577.html
>
> Call me crazy, but...
>
> A)
> Doesn't robots.txt have to be in public_html? How the hell can the robots
> read it if it's in the root folder, as they suggest in that forum?
>
> B)
> Are the Bad Bots really going to honor robots.txt in the first place? I
> mean, I know the spammers don't even need to un-obfuscate emails as simple
> as %40 and #&64; but are they really so dumb as to honor robots.txt while
> they write their crawlers?... That's crazy.
>
> Though I guess my theory on that holds true here as well: If you catch a
> million fish every time you cast your line, are you gonna try better bait?
> No. So they don't un-obfuscate even the simplest email mask, and I guess
> some of them play nice as far as robots.txt goes, even though they are out
> to spam you. Seems silly, but that could be Reality.
>
> C)
> Aren't some of those "bad" bots also going to rule out legitimate
> scripting? Am I mistaken that he pre-emptorally denies access to any
> (legit) Python script? Hello? I'm not a fan of Python, but that seems a
> bit much. :-)
> [Just kidding. I'm ambivalent towards Python, really.]
>
> --
> Like Music?
> http://l-i-e.com/artists.htm
>
robots.txt SHOULD go in the webroot, like this:
http://l-i-e.com/robots.txt
I don't know why FuNEnD3R said that it should be above the webroot.
That is a mistake.
Dotan
http://lyricslist.com/lyrics/artist_albums/64/the_beatles.php
Beatles Song Lyrics
--- End Message ---