php-general Digest 7 May 2009 10:12:10 -0000 Issue 6108
Topics (messages 292361 through 292374):
Re: speaking of control structures...
292361 by: Marcus GnaÃ
292363 by: Shawn McKenzie
292364 by: Robert Cummings
292365 by: Robert Cummings
292367 by: Marcus GnaÃ
292368 by: Nathan Rixham
292369 by: Clancy
Re: SQL Injection - Solution
292362 by: Shawn McKenzie
SimpleXML Class
292366 by: Cesco
292370 by: Nathan Rixham
292371 by: Nathan Rixham
Remote MySQL Connecton Problems
292372 by: Ray Hauge
292374 by: Nathan Rixham
XPath 2.0 in PHP 5.3
292373 by: Raymond Irving
Administrivia:
To subscribe to the digest, e-mail:
php-general-digest-subscr...@lists.php.net
To unsubscribe from the digest, e-mail:
php-general-digest-unsubscr...@lists.php.net
To post to the list, e-mail:
php-gene...@lists.php.net
----------------------------------------------------------------------
--- Begin Message ---
Robert Cummings wrote:
> On Wed, 2009-05-06 at 12:56 +0200, Marcus Gnaß wrote:
>> Tom Worster wrote:
>>> there's a control structure i wish php had: a simple block that you can
>>> break out of, e.g.
>>
>> As Maarten pointed out you could use a function. Another alternative is
>> to use Exceptions which might be the most proper way to do it.
>
> That seems like an abuse of exceptions. But then we're already abusing
> loops. I just don't think one could say it's the proper way to do it :)
>
> Cheers,
> Rob.
Why do you think it's an abuse of exceptions? If I have a block of code
which I expect to run from the beginning to the end and I discover a
situation wher its not appropriate to continue this block of code I is
what I would call an exception. Exception don't have to be errors or
such. It's just a special situation ...
Marcus
--- End Message ---
--- Begin Message ---
Marcus Gnaß wrote:
> Robert Cummings wrote:
>> On Wed, 2009-05-06 at 12:56 +0200, Marcus Gnaß wrote:
>>> Tom Worster wrote:
>>>> there's a control structure i wish php had: a simple block that you can
>>>> break out of, e.g.
>>> As Maarten pointed out you could use a function. Another alternative is
>>> to use Exceptions which might be the most proper way to do it.
>> That seems like an abuse of exceptions. But then we're already abusing
>> loops. I just don't think one could say it's the proper way to do it :)
>>
>> Cheers,
>> Rob.
>
> Why do you think it's an abuse of exceptions? If I have a block of code
> which I expect to run from the beginning to the end and I discover a
> situation wher its not appropriate to continue this block of code I is
> what I would call an exception. Exception don't have to be errors or
> such. It's just a special situation ...
>
> Marcus
In the corner to my right, wearing black trunks, with orange and yellow
trim, Marcus Gnaaaaaaaaaß...
In the corner to my left, wearing pink trunks, trimmed in pink, Robert
Cummmmmmmmmings...
DING!
--
Thanks!
-Shawn
http://www.spidean.com
--- End Message ---
--- Begin Message ---
On Wed, 2009-05-06 at 22:23 +0200, Marcus Gnaß wrote:
> Robert Cummings wrote:
> > On Wed, 2009-05-06 at 12:56 +0200, Marcus Gnaß wrote:
> >> Tom Worster wrote:
> >>> there's a control structure i wish php had: a simple block that you can
> >>> break out of, e.g.
> >>
> >> As Maarten pointed out you could use a function. Another alternative is
> >> to use Exceptions which might be the most proper way to do it.
> >
> > That seems like an abuse of exceptions. But then we're already abusing
> > loops. I just don't think one could say it's the proper way to do it :)
> >
> > Cheers,
> > Rob.
>
> Why do you think it's an abuse of exceptions? If I have a block of code
> which I expect to run from the beginning to the end and I discover a
> situation wher its not appropriate to continue this block of code I is
> what I would call an exception. Exception don't have to be errors or
> such. It's just a special situation ...
While exceptions can certainly be used in this context and in a valid
manner, there's a fine line between an exception and a condition. The OP
was processing code that didn't appear exceptional, he was merely
managing flow control of the logic. This is a condition, not an
exception.
Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP
--- End Message ---
--- Begin Message ---
On Wed, 2009-05-06 at 15:50 -0500, Shawn McKenzie wrote:
> Marcus Gnaß wrote:
> > Robert Cummings wrote:
> >> On Wed, 2009-05-06 at 12:56 +0200, Marcus Gnaß wrote:
> >>> Tom Worster wrote:
> >>>> there's a control structure i wish php had: a simple block that you can
> >>>> break out of, e.g.
> >>> As Maarten pointed out you could use a function. Another alternative is
> >>> to use Exceptions which might be the most proper way to do it.
> >> That seems like an abuse of exceptions. But then we're already abusing
> >> loops. I just don't think one could say it's the proper way to do it :)
> >>
> >> Cheers,
> >> Rob.
> >
> > Why do you think it's an abuse of exceptions? If I have a block of code
> > which I expect to run from the beginning to the end and I discover a
> > situation wher its not appropriate to continue this block of code I is
> > what I would call an exception. Exception don't have to be errors or
> > such. It's just a special situation ...
> >
> > Marcus
>
> In the corner to my right, wearing black trunks, with orange and yellow
> trim, Marcus Gnaaaaaaaaaß...
> In the corner to my left, wearing pink trunks, trimmed in pink, Robert
> Cummmmmmmmmings...
>
> DING!
Is that your fantasy Shawn? Me in a boxing ring in pink trim?? *shudder*
;)
Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP
--- End Message ---
--- Begin Message ---
Robert Cummings wrote:
> On Wed, 2009-05-06 at 22:23 +0200, Marcus Gnaß wrote:
>> Robert Cummings wrote:
>>> On Wed, 2009-05-06 at 12:56 +0200, Marcus Gnaß wrote:
>>>> Tom Worster wrote:
>>>>> there's a control structure i wish php had: a simple block that you can
>>>>> break out of, e.g.
>>>>>
>>>> As Maarten pointed out you could use a function. Another alternative is
>>>> to use Exceptions which might be the most proper way to do it.
>>>>
>>> That seems like an abuse of exceptions. But then we're already abusing
>>> loops. I just don't think one could say it's the proper way to do it :)
>>>
>> Why do you think it's an abuse of exceptions? If I have a block of code
>> which I expect to run from the beginning to the end and I discover a
>> situation where its not appropriate to continue this block of code I is
>> what I would call an exception. Exception don't have to be errors or
>> such. It's just a special situation ...
>
> While exceptions can certainly be used in this context and in a valid
> manner, there's a fine line between an exception and a condition. The OP
> was processing code that didn't appear exceptional, he was merely
> managing flow control of the logic. This is a condition, not an
> exception.
Agreed! He wrote:
if ( condition )
break;
Although I had the impression that he expected the whole block of code
to be executed and just wanted to break from this block in an
exceptional situation.
--- End Message ---
--- Begin Message ---
Robert Cummings wrote:
On Wed, 2009-05-06 at 08:41 -0400, Tom Worster wrote:
On 5/6/09 7:05 AM, "Robert Cummings" <rob...@interjinn.com> wrote:
That seems like an abuse of exceptions. But then we're already abusing
loops. I just don't think one could say it's the proper way to do it :)
i don't have a lot of interest in "the proper way" to do things. i'm
interested in how other programmers actually do things.
I highly doubt they use exceptions.
lol hello - I always seem to want to reply to your posts Rob!
with exceptions.. if you're using an n-tier architecture then exceptions
are the best thing to use here, you've got an exceptional state where
criteria isn't met and this exception should be caught by the display
layer and handled.
But this isn't a discussion with an OOP variant it's more procedural, so
def out of place imho.
at the same time.. the functionality required and what is essentially a
want for advanced separation of concerns is very oop so..
really.. this could easily be solved with OOP and it'd be an elegant
reusable solution
regards!
--- End Message ---
--- Begin Message ---
On Wed, 06 May 2009 08:54:14 -0400, f...@thefsb.org (Tom Worster) wrote:
.......
>clancy, i can't argue with you. my desired usage of break is really just a
>cover-up for a goto. i know.
>
>it makes no logical sense but i think i'd sooner adopt oop than gotos. my
>mom taught me to program back in the late 70s and early 80s. she was an old
>hand. when FORTRAN 4 came out she thought it was the bees knees. when Z80
>micros with MS-BASIC came out, she thought they were cute. when turbo pascal
>came out on CP/M, she was impressed and taught me to quit using gotos.
>
>so while it makes no logical sense, perhaps you can see that it makes
>emotional sense.
>
I can understand your reluctance to disregard your mother's advice, but
unfortunately she
had been brainwashed to accept the dogma of the day. I could never understand
the hysteria
relating to GOTO. Certainly it could be abused, as I knew to my cost, but it is
clear and
explicit, whereas both break and exception are disguised GOTO's with
ill-defined targets.
I started programming in 1967, in Fortran. There were only the most basic
computer
manuals, and CSIRO (for whom I worked) had a little computer (a CDC3200, with
32K of 24
bit words, and costing only $500,000) in each capital city, and a big computer
(a CDC3600,
with 64K of 48 bit words, and costing $2 million) in Canberra. Our local
computer was at
Clayton, and I worked at Highett, so a courier collected our punch cards twice
a day and
took them to the local computer, then brought back the results of the previous
run, giving
effectively one and a half runs a day.
When I got ambitious, and needed to use the big computer, my cards were put on
to mag tape
at Clayton, and flown to Canberra, where they were run through the 3600
overnight, and the
results written back to mag tape. Next morning the tapes were flown back to
Melbourne,
driven to Clayton, run through the 3200 to produce listings, and these were
then delivered
back to Highett. The flights were often delayed by fog in Canberra, and on
average we got
three runs a week.
Programming was in its infancy, and the idea of using a stack to handle
subroutines had
not been introduced (at least by CDC). The Fortran provided an assigned GOTO,
which really
was the perfect instruction for writing 'write only' code. It also permitted
you to jump
indiscriminately into, or out of, loops and subroutines, and it was probably
abuse of
these options which gave the GOTO its bad name.
I was developing a program for analysing linear electronic circuits, and
effectively
developed my own interpreted language. The program was very simple; it
consisted of a loop
containing three assigned GOTO's:
start: assign begin to switch_one
assign ........
next: read the next character
if it's a number, GOTO switch_one
if it's a punctuation mark, GOTO switch_two
GOTO switch_three
begin:
.....
GOTO next
end:
I left CSIRO in 1973, and did not have access to a big computer until about
1983. By this
time the assigned GOTO had long since vanished, and I had great difficulty
understanding
my original logic, until I unrolled the inner loop into a logical progression
through the
possible inputs.
For the next 20 years most of my programming was in 8x86 MASM. This also had
the GOTO, and
I was able to write extremely complex programs, despite its inherent verbosity,
by
developing subroutines to handle all the basic procedures, and using GOTO's to
define the
control structure.
--- End Message ---
--- Begin Message ---
Andrew Ballard wrote:
> On Wed, May 6, 2009 at 2:25 PM, Shawn McKenzie <nos...@mckenzies.net> wrote:
>> Igor Escobar wrote:
>>> Yeah yeah, i understood that, but, the point is... i sad previously, my
>>> function is not tied to any database.
>>>
>>> Is a generic function, i dont know who be use this, so i don't know, what is
>>> your data base so, i can't use functions like mysql_real_scape_string etc...
>> Then the best you can do is replace mysql_real_scape_string() with
>> addslashes() or possibly addcslashes() and build your own list.
>>
>>
>
> You can't just use addslashes() or addcslashes(). You have to know
> what database you are using because the escape sequences are
> different. In MySQL, single quote characters are escaped by a
> backslash. In SQL Server, they are escaped by doubling them.
>
> There are a lot of libraries available that already do this. If
> someone wants to write yet another one, it would probably be
> worthwhile to dissect some of those existing libraries to see how they
> handle work under the hood.
>
> Andrew
Good points. I haven't had much experience with any DB other than mysql
or sqlite. Without knowing the DB, you'll either need to use one of
these libraries or convert the chars to something else like html entities.
--
Thanks!
-Shawn
http://www.spidean.com
--- End Message ---
--- Begin Message ---
Could you help me clarify one thing that I don't understand... let's
put it simple, just imagine that I have a tiny XML document with a
list of movies:
<movies>
<title>
<i>Gone</i> with <b>the</b> wind
</title>
</movies>
I want to read this XML file and write the name of the first (and
only) movie in the list; for this reason I have choose to use
SimpleXML since it was looking quite user-friendly.
But there's a thing I don't understand... when I have some children,
how do I understand which is the first child and which is the last ? I
have tried to write this, but I'm getting a wrong result: instead of
"Gone with the wind" I got "with wind Gone the", because I understand
that the tag <title> contains all the text that is not formatted, and
then it writes all the children of <title>: <i>Gone</i> and <b>the</b>
<?php
$xml = new SimpleXMLElement("<movies><title><i>Gone</i> with <b>the</
b> wind</title></movies>");
echo ($xml->title . " ");
foreach ($xml->title->children() as $element) {
echo ($element . " ");
}
// Returns "with wind Gone the"
?>
I'm using PHP 5.2.5, could you tell me what am I doing wrong ? Thank you
--- End Message ---
--- Begin Message ---
Cesco wrote:
Could you help me clarify one thing that I don't understand... let's put
it simple, just imagine that I have a tiny XML document with a list of
movies:
<movies>
<title>
<i>Gone</i> with <b>the</b> wind
</title>
</movies>
I want to read this XML file and write the name of the first (and only)
movie in the list; for this reason I have choose to use SimpleXML since
it was looking quite user-friendly.
But there's a thing I don't understand... when I have some children, how
do I understand which is the first child and which is the last ? I have
tried to write this, but I'm getting a wrong result: instead of "Gone
with the wind" I got "with wind Gone the", because I understand that the
tag <title> contains all the text that is not formatted, and then it
writes all the children of <title>: <i>Gone</i> and <b>the</b>
<?php
$xml = new SimpleXMLElement("<movies><title><i>Gone</i> with
<b>the</b> wind</title></movies>");
echo ($xml->title . " ");
foreach ($xml->title->children() as $element) {
echo ($element . " ");
}
// Returns "with wind Gone the"
?>
I'm using PHP 5.2.5, could you tell me what am I doing wrong ? Thank you
cdata
<movies>
<title>
<![CDATA[<i>Gone</i> with <b>the</b> wind]]>
</title>
</movies>
--- End Message ---
--- Begin Message ---
Cesco wrote:
Could you help me clarify one thing that I don't understand... let's put
it simple, just imagine that I have a tiny XML document with a list of
movies:
<movies>
<title>
<i>Gone</i> with <b>the</b> wind
</title>
</movies>
I want to read this XML file and write the name of the first (and only)
movie in the list; for this reason I have choose to use SimpleXML since
it was looking quite user-friendly.
But there's a thing I don't understand... when I have some children, how
do I understand which is the first child and which is the last ? I have
tried to write this, but I'm getting a wrong result: instead of "Gone
with the wind" I got "with wind Gone the", because I understand that the
tag <title> contains all the text that is not formatted, and then it
writes all the children of <title>: <i>Gone</i> and <b>the</b>
<?php
$xml = new SimpleXMLElement("<movies><title><i>Gone</i> with
<b>the</b> wind</title></movies>");
echo ($xml->title . " ");
foreach ($xml->title->children() as $element) {
echo ($element . " ");
}
// Returns "with wind Gone the"
?>
I'm using PHP 5.2.5, could you tell me what am I doing wrong ? Thank you
cdata
<movies>
<title>
<![CDATA[<i>Gone</i> with <b>the</b> wind]]>
</title>
</movies>
--- End Message ---
--- Begin Message ---
Hello everyone,
I've run into a bit of a sticky situation trying to connect to a remote
MySQL database. Here's the background:
Connecting from the command line on the web server works.
Connecting from a different vhost works.
There's no information in mysql_error. In fact, mysql_select_db('db')
or die(mysql_error()); doesn't produce any output.
The only way I know this isn't working is when I try to run a query, the
result resource is NULL.
If I copy the contents of the query and run it on the command line, from
the web server, I get the results I expected.
I manage both servers. I added the new login on the MySQL server and
also ran flush privileges. I've gone so far as to reboot both the MySQL
process and the apache process.
The versions of MySQL are slightly different 5.0.24a (web) vs 5.0.36(db).
It's getting late and I'm just grasping for straws.
Thanks!
Ray
--- End Message ---
--- Begin Message ---
Ray Hauge wrote:
Hello everyone,
I've run into a bit of a sticky situation trying to connect to a remote
MySQL database. Here's the background:
Connecting from the command line on the web server works.
Connecting from a different vhost works.
There's no information in mysql_error. In fact, mysql_select_db('db')
or die(mysql_error()); doesn't produce any output.
The only way I know this isn't working is when I try to run a query, the
result resource is NULL.
If I copy the contents of the query and run it on the command line, from
the web server, I get the results I expected.
I manage both servers. I added the new login on the MySQL server and
also ran flush privileges. I've gone so far as to reboot both the MySQL
process and the apache process.
The versions of MySQL are slightly different 5.0.24a (web) vs 5.0.36(db).
It's getting late and I'm just grasping for straws.
Thanks!
Ray
and thus:
database server works - yes
user and login works locally - yes
user and login works remotely - yes
user and login works on box in question - yes
further debug:
do mysql connections work for any host at all in php? - todo
is the mysql module for php installed - todo check phpinfo() output
is error reporting enabled - todo set error_reporting to E_ALL
does a simple query such as "show databases" return any results
is query properly formatted and are variables properly replaced in php
version - todo check
I'd reckon that by the time you've checked all the above - you'll have
your own solution :)
regards!
--- End Message ---
--- Begin Message ---
Hi,
Does any one knows if XPath 2.0 will be supported in 5.3?
__
Raymond Irving
--- End Message ---