php-general Digest 23 May 2011 20:46:08 -0000 Issue 7325

Topics (messages 313088 through 313124):

Re: Closing Session (Revisited)
        313088 by: Pete Ford

Re: Date validation
        313089 by: Pete Ford
        313092 by: tedd
        313100 by: Pete Ford
        313108 by: Tamara Temple
        313110 by: Andrew Ballard

strcmp()?
        313090 by: tedd
        313091 by: Joshua Kehn
        313093 by: tedd
        313094 by: Joshua Kehn
        313095 by: Jay Blanchard
        313096 by: Ford, Mike
        313097 by: Richard Quadling
        313098 by: Alexey Bovanenko
        313102 by: Joshua Kehn
        313103 by: tedd
        313104 by: tedd
        313105 by: Alex Nikitin
        313106 by: Ford, Mike
        313107 by: Joshua Kehn
        313109 by: Joshua Kehn
        313112 by: Richard Quadling

Re: context when calling non static method of class in a static way
        313099 by: Simon Hilz

best practise accessing object's attributes from objects itself
        313101 by: Simon Hilz

Contract Example
        313111 by: Floyd Resler
        313113 by: Jonesy
        313114 by: Floyd Resler
        313115 by: tedd
        313118 by: Floyd Resler

Re: PHP Brainteasers 2011
        313116 by: Daniel Brown
        313123 by: tedd

Posts that include bracket OT bracket
        313117 by: tedd
        313121 by: Daniel Brown
        313124 by: Daevid Vincent

htaccess question
        313119 by: Al
        313120 by: admin.buskirkgraphics.com
        313122 by: Alex Nikitin

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 ---
On 22/05/11 06:46, Roger Riordan wrote:
On Thu, 05 May 2011 08:28:53 -0400, sstap...@mnsi.net (Steve Staples) wrote:

On Thu, 2011-05-05 at 21:41 +1000, Roger Riordan wrote:

I have developed a common engine which I use for several different websites. I 
had been
using PHP 5.2.? and IE6 (yes; I know!), and had been able to have multiple 
sessions open
at once, displaying the same or different websites, without them interfering 
with each
other. This was incredibly useful; I could be looking at, or even edit, 
different parts of
the same, or different, websites simultaneously without any problems.

But I recently had a hard disk crash and had to re-install all the system 
software. Now I
have PHP 5.3 and IE 8, and find that if I try to do this the various sessions 
interfere
with each other. From the above comment I gather that this is because IE 8 
combines all
the instances, whereas previously each instance was treated as a different user.

Is there any simple way to make IE 8 treat each instance as a new user, or 
should I switch
to Chrome and use the Incognito feature?

Roger Riordan AM
http://www.corybas.com/


The Incognito feature wont give you the results you're looking for.
> From my experience, the incognito window(s) and tab(s) share the same
memory/cookie/session space, which is different from the main window...
which means you will run into the same issue.

Once you close all your incognito windows/tabs, you will release those
cookies/sessions/memory space and if you open a new one afterwards, then
you will be fine, but if one tabs stays open, no go :(

Have you looked at the http://ca3.php.net/session_name function, and
putting that into your site just after your session_start() ?  I believe
that will fix your issues (as long as your session names are unique),
but i am not 100% sure.

Steve


Thank you for this suggestion. This has solved the more serious half of my 
problems; I can
easily generate a different session name for each website, so that the various 
websites
don't interfere with each other, but I have not been able to devise a way to 
differentiate
between multiple sessions of the same website.

For example, if I open one copy of a website as a visitor I am shown as 
Visitor, but if I
then open another window, and log in as Manager, then go back to the first 
window I am
shown as Manager (with appropriate privileges) there also.

The only way I can think of to overcome this would be to generate a new named 
session
every time I log in, and then to pass the session name as a parameter every 
time I load a
new page. Unfortunately my program is sufficiently complicated that this is 
effectively
impractical, as it would involve tracking down and modifying every point in the 
program at
which a new page can be launched.

It also has a theoretical disadvantage that if someone bookmarks a page they 
will book
mark the session name, but this can fairly readily be overcome.

Is there any alternative way in which a different session name (or equivalent 
flag) can be
attached to each instance of the browser?

(Effectively these problems only affect the developer, as they only apply to 
multiple
instances of the same browser on the same PC.)


PS. At this stage I devised a really nasty kludge, which enables me to run 
multiple copies
without them interfering. In my program new pages are always launched by a 
command of the
general type:

http://localhost/cypalda.com/index.php?level=1&item=22

This loads the file index.php, which is a very brief file in the public 
directory
(cypalda.com in this case). It sets a couple of constants and then transfers 
control to a
file Begin.php, in a private directory. This in turn sets up a whole lot more 
constants,
and then transfers control to the main program, which is common to 5 different 
websites.

I realised that if I specify the session name in index.php, I can make several 
copies of
this file, e.g. index.php, index1.php, index2.php, each of which specified a 
different
session name. I thought this still left me the problem of modifying all the 
points at
which a new page was launched, but then I found that by great good fortune (or 
foresight!)
I had defined a constant $home_page = index.php, and always launched a new page 
with the
basic command
echo ('<a href="'.$home_page.'?ident=' .......>');

So all I had to do to achieve the desired outcome was to specify a different 
$homepage in
each copy of index.php. Then, once I had launched a particular copy of 
index.php, that
instance of the browser would always load the session appropriate to that copy.

Even better, if I upload the various versions of index.php, I can run multiple 
copies of
the public website on the same PC without them interfering.


Roger Riordan AM
http://www.corybas.com/

Depending upon how your session persistence works, can you not just specify a different location to store session data for each possible mode of login? I have an application which does something similar, and uses a simple file store for the session data, so I have 'Manager' session data stored in /tmp/Manager/... and 'User' session data stored in /tmp/User/... (for example). It does rather depend on your Manager and User applications not expecting to cross over: that is, a Manager can't switch to User mode in the same session.


--
Peter Ford, Developer                 phone: 01580 893333 fax: 01580 893399
Justcroft International Ltd.                              www.justcroft.com
Justcroft House, High Street, Staplehurst, Kent   TN12 0AH   United Kingdom
Registered in England and Wales: 2297906
Registered office: Stag Gates House, 63/64 The Avenue, Southampton SO17 1XS

--- End Message ---
--- Begin Message ---
On 20/05/11 16:29, Geoff Lane wrote:
On Friday, May 20, 2011, Peter Lind wrote:

Try:

$date = new DateTime($date_string_to_validate);
echo $date->format('Y-m-d');

Many thanks. Unfortunately, as I mentioned in my OP, the DateTime
class seems to be 'broken' for my purposes because it uses strtotime()
to convert input strings to date/time. Rather than fail when presented
with an invalid date, strtotime() returns the 'best fit' if possible.
This can be seen from:

$date = new DateTime('30 Feb 1999');
echo $date->format('Y-m-d');

which results in "1999-03-02" even though 30 Feb is an invalid date.


If you could programmatically determine the format of the input, you could parse the date using DateTime and then rewrite it using the same format as the input, and compare those. Now that starts to work if you can *control* the format of the input, or at least limit it to some familiar options.

So maybe:

$userInput = '30 Feb 1999';
$dateTest = new DateTime($userInput);
if ($userInput===$dateTest->format('Y-m-d') ||
    $userInput===$dateTest->format('d M Y'))
{
        echo 'Date is valid';
}
else
{
        echo 'Not valid';
}

It starts to get logn-winded after a while, and doesn't rule out ambiguous 
cases...
Or split the date input into pieces in the form (if possible) and then you can validate the date how you like

$userInput = $_POST['year'].'-'.$_POST['month'].'-'.$_POST['day'];
$dateTest = new DateTime($userInput);
if ($userInput===$dateTest->format('Y-m-d'))
{
        echo 'Date is valid';
}
else
{
        echo 'Not valid';
}


Finally, for some applications I have made an AJAX (javascript + PHP) implementation which provides feedback to the user as they type in the date field: every time a character is typed in the box, the backend is asked to parse it and then format it in an unambiguous way and send it back to the client. That way the user can *see* if what they are typing is valid... Of course, you *still* have to validate it when it's posted (and the network overhead might be too much).



--
Peter Ford, Developer                 phone: 01580 893333 fax: 01580 893399
Justcroft International Ltd.                              www.justcroft.com
Justcroft House, High Street, Staplehurst, Kent   TN12 0AH   United Kingdom
Registered in England and Wales: 2297906
Registered office: Stag Gates House, 63/64 The Avenue, Southampton SO17 1XS

--- End Message ---
--- Begin Message ---
At 9:47 AM +0100 5/23/11, Pete Ford wrote:
Finally, for some applications I have made an AJAX (javascript + PHP) implementation which provides feedback to the user as they type in the date field: every time a character is typed in the box, the backend is asked to parse it and then format it in an unambiguous way and send it back to the client. That way the user can *see* if what they are typing is valid... Of course, you *still* have to validate it when it's posted (and the network overhead might be too much).

That would be interesting to see.

With a little work, I envision a way to alleviate the Europe/US date format difference. (i.e., day/month/year : Europe vs month/day/year : US).

As the user typed in the date, the day/month problem could be shown via string-month (i.e., Jan... ).

How does yours work?

Cheers,

tedd

--
-------
http://sperling.com/

--- End Message ---
--- Begin Message ---
On 23/05/11 13:12, tedd wrote:
At 9:47 AM +0100 5/23/11, Pete Ford wrote:
Finally, for some applications I have made an AJAX (javascript + PHP)
implementation which provides feedback to the user as they type in the
date field: every time a character is typed in the box, the backend is
asked to parse it and then format it in an unambiguous way and send it
back to the client. That way the user can *see* if what they are
typing is valid...
Of course, you *still* have to validate it when it's posted (and the
network overhead might be too much).

That would be interesting to see.

With a little work, I envision a way to alleviate the Europe/US date
format difference. (i.e., day/month/year : Europe vs month/day/year : US).

As the user typed in the date, the day/month problem could be shown via
string-month (i.e., Jan... ).

How does yours work?

Cheers,

tedd

Ah, now you're asking.
I'll have to try and extract the code into a sanitised form for public consumption: give me a little time... But yes, the string fed back to the user gives the month as a string, to avoid confusion with numeric months.

--
Peter Ford, Developer                 phone: 01580 893333 fax: 01580 893399
Justcroft International Ltd.                              www.justcroft.com
Justcroft House, High Street, Staplehurst, Kent   TN12 0AH   United Kingdom
Registered in England and Wales: 2297906
Registered office: Stag Gates House, 63/64 The Avenue, Southampton SO17 1XS

--- End Message ---
--- Begin Message ---
Isn't this typically why date selectors are used on the front end?

--- End Message ---
--- Begin Message ---
On Mon, May 23, 2011 at 9:55 AM, Tamara Temple <tamouse.li...@gmail.com> wrote:
> Isn't this typically why date selectors are used on the front end?
>

Not really. Date selectors are intended to make data entry easier on
the front end while allowing only valid date selections, but you can't
really rely on them.

* Most date selectors rely on Javascript, which may not be available
on the client.

* From a usability perspective, using a date selector is slower than
typing the date into a text field. Accessibility is also a concern.

* Above all, your code should still validate the correctness of input
on the server regardless of anything you are doing to make things
easier in the client. There are ways around using date selectors.

Andrew

--- End Message ---
--- Begin Message ---
At 8:13 AM +0000 5/23/11, Ford, Mike wrote:
 > -----Original Message-----
 > From: tedd [mailto:tedd.sperl...@gmail.com]
 > >On Sat, 21 May 2011 09:26:02 -0400, tedd wrote:
 > >>  The function strcmp() simply evaluates two strings and reports
 > back -1, 0, or 1 depending upon their  alphabetical relationship.
 > >
 >It might do that, but don't bet your horse on it.
 >
 ><http://se.php.net/manual/en/function.strcmp.php>
 >
 > >/Nisse

 It works that way for me.

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";

Result:

   13
   -17
   1

The description of the function merely says that the result is <0, 0 or >0
-- it makes no promises about the actual value when it is non-zero.

Mike

Mike:

That's interesting. Try the same comparisons here:

http://www.webbytedd.com/lcc/citw229/string-compare.php

For me they are 1, -1, and 1.

Someone with more smarts than me* will have to figure this one out.

Cheers,

tedd

PS: * I can hear the peanut gallery saying "That won't be hard."  :-)

--
-------
http://sperling.com/

--- End Message ---
--- Begin Message ---
On May 23, 2011, at 8:00 AM, tedd wrote:

> At 8:13 AM +0000 5/23/11, Ford, Mike wrote:
>> > -----Original Message-----
>> > From: tedd [mailto:tedd.sperl...@gmail.com]
>> > >On Sat, 21 May 2011 09:26:02 -0400, tedd wrote:
>> > >>  The function strcmp() simply evaluates two strings and reports
>> > back -1, 0, or 1 depending upon their  alphabetical relationship.
>> > >
>>> >It might do that, but don't bet your horse on it.
>>> >
>>> ><http://se.php.net/manual/en/function.strcmp.php>
>>> >
>> > >/Nisse
>>> 
>>> It works that way for me.
>> 
>> 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";
>> 
>> Result:
>> 
>>   13
>>   -17
>>   1
>> 
>> The description of the function merely says that the result is <0, 0 or >0
>> -- it makes no promises about the actual value when it is non-zero.
>> 
>> Mike
> 
> Mike:
> 
> That's interesting. Try the same comparisons here:
> 
> http://www.webbytedd.com/lcc/citw229/string-compare.php
> 
> For me they are 1, -1, and 1.
> 
> Someone with more smarts than me* will have to figure this one out.
> 
> Cheers,
> 
> tedd
> 
> PS: * I can hear the peanut gallery saying "That won't be hard."  :-)
> 
> -- 
> -------
> http://sperling.com/

Might that have something to do with the version of PHP running? 

Regards,

-Josh
____________________________________
Joshua Kehn | josh.k...@gmail.com
http://joshuakehn.com


--- End Message ---
--- Begin Message ---
 > Mike:

 That's interesting. Try the same comparisons here:

 http://www.webbytedd.com/lcc/citw229/string-compare.php

 > For me they are 1, -1, and 1.

Might that have something to do with the version of PHP running?


-Josh


-Josh:

I've written this on two different servers.

One is Version 5.2.15 and the other is version 5.2.5 and they both report the same results.

Cheers,

tedd

--
-------
http://sperling.com/

--- End Message ---
--- Begin Message ---
On May 23, 2011, at 8:17 AM, tedd wrote:

>> > Mike:
>>> 
>>> That's interesting. Try the same comparisons here:
>>> 
>>> http://www.webbytedd.com/lcc/citw229/string-compare.php
>>> 
>> > For me they are 1, -1, and 1.
>> 
>> Might that have something to do with the version of PHP running?
>> 
>> 
>> -Josh
> 
> 
> -Josh:
> 
> I've written this on two different servers.
> 
> One is Version 5.2.15 and the other is version 5.2.5 and they both report the 
> same results.
> 
> Cheers,
> 
> tedd


I just checked under 5.3.2 and it gives the same -1, 0, 1 results. 

Regards,

-Josh
____________________________________
Joshua Kehn | josh.k...@gmail.com
http://joshuakehn.com


--- End Message ---
--- Begin Message ---
[snip]....[/snip]

5.2.9 yields -1, 0, 1

--- End Message ---
--- Begin Message ---
> -----Original Message-----
> From: Joshua Kehn [mailto:josh.k...@gmail.com]
> Sent: 23 May 2011 13:04
> 
> On May 23, 2011, at 8:00 AM, tedd wrote:
> 
> > At 8:13 AM +0000 5/23/11, Ford, Mike wrote:

> >>   echo strcmp('These are nearly equal', 'These are almost
> equal'), "\n";
> >>   echo strcmp('different', 'unequal'), "\n";
> >>   echo strcmp('b', 'a'), "<br />\n";
> >>
> >> Result:
> >>
> >>   13
> >>   -17
> >>   1
> >>
> >> The description of the function merely says that the result is
> <0, 0 or >0
> >> -- it makes no promises about the actual value when it is non-
> zero.
> >>
> >> Mike
> >
> > Mike:
> >
> > That's interesting. Try the same comparisons here:
> >
> > http://www.webbytedd.com/lcc/citw229/string-compare.php
> >
> > For me they are 1, -1, and 1.
> >
> > Someone with more smarts than me* will have to figure this one
> out.
> >
> > Cheers,
> >
> > tedd
> >
> > PS: * I can hear the peanut gallery saying "That won't be hard."
> :-)
> >
> > --
> > -------
> > http://sperling.com/
> 
> Might that have something to do with the version of PHP running?

Possibly -- or even the result returned by the underlying C strcmp()
for any given architecture/compiler combination, which would like as
not be even more variable.

I think the lesson is, if writing portable code, always allow for
results which might be outside of the [-1, 0, 1] set.

(Incidentally, tedd, your test script has the < > signs the wrong way
round in the output; plus which they should be &lt; &gt; anyway; plus
plus which, you are not applying htmlspecialchars() or whatever to
your echoed user input, so values such as

   "><!--"

break your page, and I'm sure something more malicious could be cooked
up were I so inclined... :( .)

Cheers!

Mike

 -- 
Mike Ford,
Electronic Information Developer, Libraries and Learning Innovation,  
Leeds Metropolitan University, C507 City Campus, 
Portland Way, LEEDS,  LS1 3HE,  United Kingdom 
Email: m.f...@leedsmet.ac.uk 
Tel: +44 113 812 4730





To view the terms under which this email is distributed, please go to 
http://disclaimer.leedsmet.ac.uk/email.htm

--- End Message ---
--- Begin Message ---
On 23 May 2011 13:24, Joshua Kehn <josh.k...@gmail.com> wrote:
> On May 23, 2011, at 8:17 AM, tedd wrote:
>
>>> > Mike:
>>>>
>>>> That's interesting. Try the same comparisons here:
>>>>
>>>> http://www.webbytedd.com/lcc/citw229/string-compare.php
>>>>
>>> > For me they are 1, -1, and 1.
>>>
>>> Might that have something to do with the version of PHP running?
>>>
>>>
>>> -Josh
>>
>>
>> -Josh:
>>
>> I've written this on two different servers.
>>
>> One is Version 5.2.15 and the other is version 5.2.5 and they both report 
>> the same results.
>>
>> Cheers,
>>
>> tedd
>
>
> I just checked under 5.3.2 and it gives the same -1, 0, 1 results.
>
> Regards,
>
> -Josh
> ____________________________________
> Joshua Kehn | josh.k...@gmail.com
> http://joshuakehn.com
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

Just tested the code below on Windows, using official releases (and
some RCs also).

<?php
echo
        PHP_VERSION, ' ',
        strcmp('These are nearly equal', 'These are almost equal'), ' ',
        strcmp('different', 'unequal'), ' ',
        strcmp('b', 'a');
?>

And for all of the V4 and V5 releases I've got, the result is the same...

-1 1 -1


-- 
Richard Quadling
Twitter : EE : Zend : PHPDoc
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY : bit.ly/lFnVea

--- End Message ---
--- Begin Message ---
I checked on php 5.2.4-2 (ubuntu5.12). It returns 1,-1,1

On Mon, May 23, 2011 at 4:00 PM, tedd <t...@sperling.com> wrote:

> At 8:13 AM +0000 5/23/11, Ford, Mike wrote:
>
>>  > -----Original Message-----
>>  > From: tedd [mailto:tedd.sperl...@gmail.com]
>>  > >On Sat, 21 May 2011 09:26:02 -0400, tedd wrote:
>>  > >>  The function strcmp() simply evaluates two strings and reports
>>  > back -1, 0, or 1 depending upon their  alphabetical relationship.
>>  > >
>>
>>>  >It might do that, but don't bet your horse on it.
>>>  >
>>>  ><http://se.php.net/manual/en/function.strcmp.php>
>>>  >
>>>
>>  > >/Nisse
>>
>>>
>>>  It works that way for me.
>>>
>>
>> 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";
>>
>> Result:
>>
>>   13
>>   -17
>>   1
>>
>> The description of the function merely says that the result is <0, 0 or >0
>> -- it makes no promises about the actual value when it is non-zero.
>>
>> Mike
>>
>
> Mike:
>
> That's interesting. Try the same comparisons here:
>
> http://www.webbytedd.com/lcc/citw229/string-compare.php
>
> For me they are 1, -1, and 1.
>
> Someone with more smarts than me* will have to figure this one out.
>
> Cheers,
>
> tedd
>
> PS: * I can hear the peanut gallery saying "That won't be hard."  :-)
>
> --
> -------
> http://sperling.com/
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


-- 
With regards,
Alexei Bovanenko

--- End Message ---
--- Begin Message ---
On May 23, 2011, at 9:28 AM, Alex Nikitin wrote:

> There is an interesting note in the comments for strcmp:
> "Well, I am using PHP 4.0 and both strcmp and strcasecmp appear to be giving 
> me very arbitrary and incomprehensible results. When I input strings, it 
> appears that "equal" strings return "1", as well as some unequal strings, and 
> that if the first argument is "smaller" then I *tend* to get negative 
> numbers, but sometimes I get 1, and if larger I *tend* to get numbers larger 
> than 1.. "
> 
> 
> Guessing that earlier versions of php 4 and before would give the results 
> that would have values other then 1, 0, -1, i looked through the change log, 
> but nothing immediately jumped out, there was a lot of mbstring work done, 
> and they did add the nat comparison functions, and play with the pcre engine 
> a bit, which could have caused this as an unintended result for a few 
> versions, i think though it was a bug at some point, so, maybe a php dev 
> would chime in if they remember...?
> 
> 
> -- Alex --
> --
> The trouble with programmers is that you can never tell what a programmer is 
> doing until it’s too late.  ~Seymour Cray


All this confusion makes me glad that I'm using === for equality checks instead 
of strcmp. 

Regards,

-Josh
____________________________________
Joshua Kehn | josh.k...@gmail.com
http://joshuakehn.com


--- End Message ---
--- Begin Message ---
At 1:06 PM +0000 5/23/11, Ford, Mike wrote:

(Incidentally, tedd, your test script has the < > signs the wrong way
round in the output; plus which they should be &lt; &gt; anyway; plus
plus which, you are not applying htmlspecialchars() or whatever to
your echoed user input, so values such as

   "><!--"

break your page, and I'm sure something more malicious could be cooked
up were I so inclined... :( .)

Mike

Mike:

Thanks.

The "which way the arrows point" thing is because I'm dyslexic. While I know that "a" appears before "b", it's difficult for me to think of 'a' being less than 'b' -- UNLESS -- I think in terms of their ASCII values and then everything makes sense -- but that's a step away from deciding < or >. IOW, it's a two step process for me to realize which way the arrows point.

As for the htmlspecialchars(), you are absolutely right. The demo was for my students and I didn't want to confuse them. However, I have changed the code to htmlentities(). They probably should start learning basic security from the get-go (as should I).

Cheers,

tedd

--
-------
http://sperling.com/

--- End Message ---
--- Begin Message ---
At 9:32 AM -0400 5/23/11, Joshua Kehn wrote:

All this confusion makes me glad that I'm using === for equality checks instead of strcmp.

-Josh

-Josh:

Yes, but what if you were sorting? I know you could use sort(), but there might be logic where a strcmp() would better solve the problem.

Cheers,

tedd
--
-------
http://sperling.com/

--- End Message ---
--- Begin Message ---
On Mon, May 23, 2011 at 9:32 AM, Joshua Kehn <josh.k...@gmail.com> wrote:

>
> On May 23, 2011, at 9:28 AM, Alex Nikitin wrote:
>
> > There is an interesting note in the comments for strcmp:
> > "Well, I am using PHP 4.0 and both strcmp and strcasecmp appear to be
> giving me very arbitrary and incomprehensible results. When I input strings,
> it appears that "equal" strings return "1", as well as some unequal strings,
> and that if the first argument is "smaller" then I *tend* to get negative
> numbers, but sometimes I get 1, and if larger I *tend* to get numbers larger
> than 1.. "
> >
> >
> > Guessing that earlier versions of php 4 and before would give the results
> that would have values other then 1, 0, -1, i looked through the change log,
> but nothing immediately jumped out, there was a lot of mbstring work done,
> and they did add the nat comparison functions, and play with the pcre engine
> a bit, which could have caused this as an unintended result for a few
> versions, i think though it was a bug at some point, so, maybe a php dev
> would chime in if they remember...?
> >
> >
> > -- Alex --
> > --
> > The trouble with programmers is that you can never tell what a programmer
> is doing until it’s too late.  ~Seymour Cray
>
>
> All this confusion makes me glad that I'm using === for equality checks
> instead of strcmp.
>
> Regards,
>
> -Josh
> ____________________________________
> Joshua Kehn | josh.k...@gmail.com
> http://joshuakehn.com
>
>
It depends on what you need to check, josh :)

If you wanted to say find an anagram, or do a search with some typo
correction, strcmp can be many times more helpful then a ===, that said
comparing 2 strings to be equal === works about 20% quicker, so it works
better for comparing two strings for equality (or unequality) anyways. There
is no confusion, strcmp has a documented way in which it is to work in
posix-compliant languages, ISO/IEC 9899:1999, 7.21.4.2, so as long as you
follow the ISO guidelines for the scrcmp checking, your code should work
correctly...

--
The trouble with programmers is that you can never tell what a programmer is
doing until it’s too late.  ~Seymour Cray

--- End Message ---
--- Begin Message ---
> -----Original Message-----
> From: tedd [mailto:tedd.sperl...@gmail.com]
> Sent: 23 May 2011 14:41


> The "which way the arrows point" thing is because I'm dyslexic.
> While
> I know that "a" appears before "b", it's difficult for me to think
> of
> 'a' being less than 'b' -- UNLESS -- I think in terms of their ASCII
> values and then everything makes sense -- but that's a step away
> from
> deciding < or >. IOW, it's a two step process for me to realize
> which
> way the arrows point.

Yes, I remember you mentioning being dyslexic a few times on this list
before, which is partly why it was only an "incidentally" at the end.
We have a pretty hot "disability and dyslexia" unit here who don't
shrink from telling me what's good and what's bad about our website!

And, just for the record re the strcmp() debate, I'm on PHP 5.2.5,
SunOS 5.10.

Cheers!

Mike
 -- 
Mike Ford,
Electronic Information Developer, Libraries and Learning Innovation,  
Leeds Metropolitan University, C507 City Campus, 
Portland Way, LEEDS,  LS1 3HE,  United Kingdom 
E: m.f...@leedsmet.ac.uk     T: +44 113 812 4730




To view the terms under which this email is distributed, please go to 
http://disclaimer.leedsmet.ac.uk/email.htm

--- End Message ---
--- Begin Message ---
On May 23, 2011, at 9:45 AM, tedd wrote:

> At 9:32 AM -0400 5/23/11, Joshua Kehn wrote:
>> 
>> All this confusion makes me glad that I'm using === for equality checks 
>> instead of strcmp.
>> 
>> -Josh
> 
> -Josh:
> 
> Yes, but what if you were sorting? I know you could use sort(), but there 
> might be logic where a strcmp() would better solve the problem.
> 
> Cheers,
> 
> tedd
> -- 
> -------
> http://sperling.com/

Never encountered an issue using sort() as-is. 

Regards,

-Josh
____________________________________
Joshua Kehn | josh.k...@gmail.com
http://joshuakehn.com


--- End Message ---
--- Begin Message ---
On May 23, 2011, at 9:47 AM, Alex Nikitin wrote:
>  
> It depends on what you need to check, josh :)
> 
> If you wanted to say find an anagram, or do a search with some typo 
> correction, strcmp can be many times more helpful then a ===, that said 
> comparing 2 strings to be equal === works about 20% quicker, so it works 
> better for comparing two strings for equality (or unequality) anyways. There 
> is no confusion, strcmp has a documented way in which it is to work in 
> posix-compliant languages, ISO/IEC 9899:1999, 7.21.4.2, so as long as you 
> follow the ISO guidelines for the scrcmp checking, your code should work 
> correctly...
> 
> --
> The trouble with programmers is that you can never tell what a programmer is 
> doing until it’s too late.  ~Seymour Cray


It's good to know it's functionality is available in the case that I ever need 
it. 

Regards,

-Josh
____________________________________
Joshua Kehn | josh.k...@gmail.com
http://joshuakehn.com


--- End Message ---
--- Begin Message ---
On 23 May 2011 14:28, Alex Nikitin <niks...@gmail.com> wrote:
> There is an interesting note in the comments for strcmp:
> "Well, I am using PHP 4.0 and both strcmp and strcasecmp appear to be giving
> me very arbitrary and incomprehensible results. When I input strings, it
> appears that "equal" strings return "1", as well as some unequal strings,
> and that if the first argument is "smaller" then I *tend* to get negative
> numbers, but sometimes I get 1, and if larger I *tend* to get numbers larger
> than 1.. "
>
> Guessing that earlier versions of php 4 and before would give the results
> that would have values other then 1, 0, -1, i looked through the change log,
> but nothing immediately jumped out, there was a lot of mbstring work done,
> and they did add the nat comparison functions, and play with the pcre engine
> a bit, which could have caused this as an unintended result for a few
> versions, i think though it was a bug at some point, so, maybe a php dev
> would chime in if they remember...?
>
4.0.0 1 -1 1
4.0.1 1 -1 1
4.0.1 1 -1 1
4.0.2 1 -1 1
4.0.3 1 -1 1
4.0.4 1 -1 1
4.0.4pl1 1 -1 1
4.0.5 1 -1 1
4.0.6 1 -1 1
4.1.0 1 -1 1
4.1.1 1 -1 1
4.1.2 1 -1 1
4.2.0 1 -1 1
4.2.1 1 -1 1
4.2.2 1 -1 1
4.2.3RC1 1 -1 1
4.2.3RC2 1 -1 1
4.2.3 1 -1 1
4.3.0-pre2 1 -1 1
4.3.0RC1 1 -1 1
4.3.0RC2 1 -1 1
4.3.0RC3 1 -1 1
4.3.0RC4 1 -1 1
4.3.0 1 -1 1
4.3.1 1 -1 1
4.3.10 1 -1 1
4.3.11 1 -1 1
4.3.2-RC1 1 -1 1
4.3.2-RC2 1 -1 1
4.3.2RC3 1 -1 1
4.3.2 1 -1 1
4.3.3RC1 1 -1 1
4.3.3RC2 1 -1 1
4.3.3RC3 1 -1 1
4.3.3RC4 1 -1 1
4.3.3 1 -1 1
4.3.4RC1 1 -1 1
4.3.4RC2 1 -1 1
4.3.4RC3 1 -1 1
4.3.4 1 -1 1
4.3.5RC1 1 -1 1
4.3.5RC2 1 -1 1
4.3.5RC3 1 -1 1
4.3.5RC4 1 -1 1
4.3.5 1 -1 1
4.3.6RC1 1 -1 1
4.3.6RC2 1 -1 1
4.3.6RC3 1 -1 1
4.3.6 1 -1 1
4.3.7RC1 1 -1 1
4.3.7 1 -1 1
4.3.8 1 -1 1
4.3.9RC1 1 -1 1
4.3.9 1 -1 1
4.4.0 1 -1 1
4.4.1 1 -1 1
4.4.2 1 -1 1
4.4.3 1 -1 1
4.4.4 1 -1 1
4.4.5 1 -1 1
4.4.6 1 -1 1
4.4.7 1 -1 1
4.4.8 1 -1 1
4.4.9 1 -1 1

All the official versions of PHP 4 (and some RCs) for Windows.

All give the same response.

Must me a platform issue also.
-- 
Richard Quadling
Twitter : EE : Zend : PHPDoc
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY : bit.ly/lFnVea

--- End Message ---
--- Begin Message --- ah i forgot e_all doesnt include e_strict. with error_reporting(-1 / E_ALL | E_STRICT) i see the errors. so i think i am right that the use of that special behavior of php is not a good idea. thank you guys!

Am 23.05.2011 00:32, schrieb Richard Quadling:
On 22 May 2011 22:44, Simon Hilz<simon.h...@gmx.de>  wrote:
i cant reproduce that error. which php version do you use?
i've coded an example for a "behavior"-pattern:

Try with ...

<?php
error_reporting(-1);
ini_set('display_errors', 1);
class Car {
...

I get output of ...

Fuel of my new BMW with consumption 7.2l/100km: 0<br>call
TankUpBehavior::tankUp (100)<br>
Strict Standards: Non-static method TankUpBehavior::tankUp() should
not be called statically, assuming $this from incompatible context in
D:\Work\t1.php on line 50
Fuel after tank up 100 l: 100<br>call DriveBehavior::drive (24)<br>
Strict Standards: Non-static method DriveBehavior::drive() should not
be called statically, assuming $this from incompatible context in
D:\Work\t1.php on line 50
Fuel after driving 24 km: 98.272<br>




--- End Message ---
--- Begin Message ---
hi,

i was wondering if there is any best practise known how one should access the attributes of an object from the object itself. i mean, it is a good practise to write getters and setters for the attributes of an object to its interface. but is it common to modify the attributes from the object itself directly or also through the interface methods? i use the interface methods in my own classes at most times but recently i dived into zend framework and there it seems not to be usual. as zend framework is more or less a showpiece-software in php programming i'm not sure if my practises are good. are there any discussions by really focused php programmers about that?


Simon

--- End Message ---
--- Begin Message ---
I landed my first big PHP contract (yeah!) and am need of a contract or 
agreement example.  Does anyone have, or know of a good source for, 
contract/agreement examples?

Thanks!
Floyd


--- End Message ---
--- Begin Message ---
On Mon, 23 May 2011 10:39:10 -0400, Floyd Resler wrote:

> I landed my first big PHP contract (yeah!) and am need of a contract 
> or agreement example.  Does anyone have, or know of a good source for, 
> contract/agreement examples? > > Thanks! > Floyd > >

Enforceable in what country/province?

        http://www.sloperama.com/advice/entry65.html


--- End Message ---
--- Begin Message ---
On May 23, 2011, at 11:12 AM, Jonesy wrote:

> On Mon, 23 May 2011 10:39:10 -0400, Floyd Resler wrote:
> 
>> I landed my first big PHP contract (yeah!) and am need of a contract 
>> or agreement example.  Does anyone have, or know of a good source for, 
>> contract/agreement examples? > > Thanks! > Floyd > >
> 
> Enforceable in what country/province?
> 
>       http://www.sloperama.com/advice/entry65.html
> 
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 

It's the United States, state of Ohio.  And I did try to find examples on line 
before posting my question.  All I could find were examples on how to create 
PHP forms.

Thanks!
Floyd


--- End Message ---
--- Begin Message ---
At 10:39 AM -0400 5/23/11, Floyd Resler wrote:
I landed my first big PHP contract (yeah!) and am need of a contract or agreement example. Does anyone have, or know of a good source for, contract/agreement examples?

Thanks!
Floyd

Floyd:

Here's something you may want to read:

http://24ways.org/2008/contract-killer

While I don't recommend using this as an actual contract, it does give you an idea of what can happen and how you may want to consider protecting yourself.

Cheers,

tedd

--
-------
http://sperling.com/

--- End Message ---
--- Begin Message ---
On May 23, 2011, at 11:29 AM, tedd wrote:

> At 10:39 AM -0400 5/23/11, Floyd Resler wrote:
>> I landed my first big PHP contract (yeah!) and am need of a contract or 
>> agreement example.  Does anyone have, or know of a good source for, 
>> contract/agreement examples?
>> 
>> Thanks!
>> Floyd
> 
> Floyd:
> 
> Here's something you may want to read:
> 
> http://24ways.org/2008/contract-killer
> 
> While I don't recommend using this as an actual contract, it does give you an 
> idea of what can happen and how you may want to consider protecting yourself.
> 
> Cheers,
> 
> tedd
> 
> -- 
> -------
> http://sperling.com/

Excellent!  Thanks!  That article gives me enough information to fashion one of 
my own, I think.

Thanks!
Floyd


--- End Message ---
--- Begin Message ---
On Fri, May 20, 2011 at 12:55, Marc Guay <m...@jkcommunications.com> wrote:
> I imagine this one's been done before, but maybe not in the same way....

    I believe it was, but not quite the same, you're right.

        "If at first you don't succeed, try, try again."

    Nice one, Marc.



> <?php
>
>        $result = succeed();
>
>        while (!$result){
>                try{
>                        $result = succeed();
>
>                }
>                catch (Exception $e){
>                        echo $e;
>                }
>        }
>        echo "hell yeah";
>
>        function succeed(){
>                $a = rand(1,2);
>
>                switch($a){
>                        case 1:
>                                trigger_error('fml');
>                                break;
>                        case 2:
>                                return TRUE;
>                                break;
>                }
>        }
> ?>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>



-- 
</Daniel P. Brown>
Network Infrastructure Manager
http://www.php.net/

--- End Message ---
--- Begin Message ---
At 11:29 AM -0400 5/23/11, Daniel Brown wrote:
On Fri, May 20, 2011 at 12:55, Marc Guay <m...@jkcommunications.com> wrote:
 I imagine this one's been done before, but maybe not in the same way....

    I believe it was, but not quite the same, you're right.

        "If at first you don't succeed, try, try again."

"If at first you don't succeed, eat a donut -- the urge will pass."

Cheers,

tedd

--
-------
http://sperling.com/

--- End Message ---
--- Begin Message ---
Hi gang:

When did the list start rejecting subject lines that contain "[OT]"?

Cheers,

tedd

--
-------
http://sperling.com/

--- End Message ---
--- Begin Message ---
On Mon, May 23, 2011 at 11:33, tedd <tedd.sperl...@gmail.com> wrote:
> Hi gang:
>
> When did the list start rejecting subject lines that contain "[OT]"?

    At least several years ago.  It bounces back to say that off-topic
mail isn't accepted, blah, blah, blah.


-- 
</Daniel P. Brown>
Network Infrastructure Manager
http://www.php.net/

--- End Message ---
--- Begin Message ---

> -----Original Message-----
> From: paras...@gmail.com [mailto:paras...@gmail.com] On Behalf Of Daniel
> Brown
> Sent: Monday, May 23, 2011 11:20 AM
> To: tedd
> Cc: php-gene...@lists.php.net
> Subject: Re: [PHP] Posts that include bracket OT bracket
> 
> On Mon, May 23, 2011 at 11:33, tedd <tedd.sperl...@gmail.com> wrote:
> > Hi gang:
> >
> > When did the list start rejecting subject lines that contain "[OT]"?
> 
>     At least several years ago.  It bounces back to say that off-topic
> mail isn't accepted, blah, blah, blah.

It's kind of silly if you ask me as it doesn't prevent anything since any
mildly intelligent person will just omit the [OT] and re-submit (case in
point), and it prevents other users from doing any kind of email filtering
on [OT]. It's basically punishing the sender for trying to do the right
thing. *sigh*


--- End Message ---
--- Begin Message --- How can I prevent access to all files in a directory except one with an htaccess file.

I've tried several approaches found with Googling; but, none seem to work.

e.g.,
<FilesMatch "^(makeScodeImg.php)">
Order Allow,Deny
Deny from all
</FilesMatch>

This seems to me as it should deny to all except makeScodeImg.php

Thanks


--- End Message ---
--- Begin Message ---
First turn your ReWriteEngine On. 
This can be done in the particular folder to allow them access to only the
one file.
You need to understand the conditions of mod_rewrite read below.

http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html

OR 

you can just use the http://cooletips.de/htaccess/ from Germany.

It will take you through step by step in creating an htaccess.
I might suggest you do not use the password options because that to me is
not safe to use someone else's website when creating htaccess screen names
and passwords.







Richard L. Buskirk


-----Original Message-----
From: Al [mailto:n...@ridersite.org] 
Sent: Monday, May 23, 2011 11:53 AM
To: php-gene...@lists.php.net
Subject: [PHP] htaccess question

How can I prevent access to all files in a directory except one with an
htaccess 
file.

I've tried several approaches found with Googling; but, none seem to work.

e.g.,
<FilesMatch "^(makeScodeImg.php)">
Order Allow,Deny
Deny from all
</FilesMatch>

This seems to me as it should deny to all except makeScodeImg.php

Thanks


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


--- End Message ---
--- Begin Message ---
On Mon, May 23, 2011 at 11:52 AM, Al <n...@ridersite.org> wrote:

> How can I prevent access to all files in a directory except one with an
> htaccess file.
>
> I've tried several approaches found with Googling; but, none seem to work.
>
> e.g.,
> <FilesMatch "^(makeScodeImg.php)">
> Order Allow,Deny
> Deny from all
> </FilesMatch>
>
> This seems to me as it should deny to all except makeScodeImg.php
>
> Thanks
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

Also don't forget to enable override on the directory, otherwise .htaccess
wont be read at all...

http://httpd.apache.org/docs/2.0/mod/core.html

--
The trouble with programmers is that you can never tell what a programmer is
doing until it’s too late.  ~Seymour Cray

--- End Message ---

Reply via email to