Discussion:
A little confusing thing on (mistakenly) geting a offset from string with multi dim index.
\\R\\N
2014-05-13 15:22:39 UTC
Permalink
Greeting guys,

I got a problem on checking and getting a string with multi dim index (like
['blablabla']['blabla']). It confusing me, so I think I need to found an
answer to clear myself.

First of all, I known that is wrong to get something from a string using a
multi dim index or even a string index. I did it by mistakenly set a wrong
parameter. The parameter supposed to be array with string as index (That
will actually be a hashmap), but I setted a string on it.

As result, I got a warning raised: Illegal string offset.

It's normal since I use the string as index to attempt to getting something
from a string. But the strange thing is, I did the isset check before use
the index. It supposed to be hot pass the check, but it did.

So I made a shorter test here:
https://gist.github.com/raincious/682ba152dbd74537e323#file-stringisset-php

The test 1 is what I used in my application, it checks if the array index is
set and not empty in same time. A valid param for it should be like this:

$string = array(
'check' => 'yes',
); // Please ignore the variable name

But when the $string truly turned to a string, it become the source of my
question.

Please notice that, on document:
http://www.php.net/manual/en/function.isset.php says, "Checking non-numeric
offsets of strings now returns FALSE." since 5.4, and I using 5.5.

So the test 3 (isset($string['check']) one) running as expected, it returns
false. However, the test1 (isset($string['check'][0]) one) is unfortunatly
not, It actually returnning true.

I'm not a experter of PHP and I even need other people's help to read PHP
source code, but in the information from the document and the talking with
other people gives me some guts to guess the $string['check'][0] actually
will be converted into $string[(int)'check'][0] and then into $string[0][0],
so the test 1 can be pass. Is that right?

So, what I want to know is, why there has two kind of behaviour for isset?
Maybe it's better to let the isset($string['check'][0]) and
isset($string['check']) both return false?






And sorry for my english, please ask if you confused by me.

Thank you,
R
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Christoph Becker
2014-05-13 17:56:34 UTC
Permalink
Post by \\R\\N
I'm not a experter of PHP and I even need other people's help to read PHP
source code, but in the information from the document and the talking with
other people gives me some guts to guess the $string['check'][0] actually
will be converted into $string[(int)'check'][0] and then into $string[0][0],
so the test 1 can be pass. Is that right?
Yes.
Post by \\R\\N
So, what I want to know is, why there has two kind of behaviour for isset?
Maybe it's better to let the isset($string['check'][0]) and
isset($string['check']) both return false?
The behavior of isset is fine. Consider that $string['check'] is
treated as $string[0], so it evaluates to a string with only the first
character of $string. Then it is checked, whether this string has a
character at position zero. As this is true, isset returns true.

You may consider using array_key_exists() instead of isset().
--
Christoph M. Becker
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Rain Lee
2014-05-14 01:19:55 UTC
Permalink
Hi Christoph Becker,

Thank you for reply this topic.

Yes, i know to use array_key_exists, i believe i got the point.

I don't use it because it slower than isset, and isset is still needed
for checking if the variable's existing. Now i use is_array to check
if i'm testing a array for isset, so the code will be something like:

if (isset($val['key'][0]) && is_array($val)) {

and the full check will need an is_string to make sure the $val['key']
is a string. So it becomes

if (isset($val['key'][0]) && is_array($val) && is_string($val['key'])) {

The array_key_exists not making the code simpler, it will looks like:

if (isset($val) && array_key_exists('key', $val) &&
is_string($val['key']) && !empty($val['key'])) {

Or the code in document comment (with modification):
if ((isset($val['key']) || array_key_exists('key', $val)) &&
is_string($val['key']) && !empty($val['key'])) {


However, if isset($string['check'][0]) and isset($string['check']) can
both be false, i just need to do:

if (isset($val['key'][0]) && is_string($val['key'])) {

It's saving life and time. And i think it's intuitively making sense,
because the string offset 'key' shouldn't be exist for a string,
therefore the ['key'][0] should not be exist too.

I think the convert that cause the 'key' become 0 is ... not a good
idea. But my experience on PHP is so little, maybe there is some
reason for it that i never know.

Don't know what's the opinion of those guys inside the PHP.
Post by Christoph Becker
Post by \\R\\N
I'm not a experter of PHP and I even need other people's help to read PHP
source code, but in the information from the document and the talking with
other people gives me some guts to guess the $string['check'][0] actually
will be converted into $string[(int)'check'][0] and then into $string[0][0],
so the test 1 can be pass. Is that right?
Yes.
Post by \\R\\N
So, what I want to know is, why there has two kind of behaviour for isset?
Maybe it's better to let the isset($string['check'][0]) and
isset($string['check']) both return false?
The behavior of isset is fine. Consider that $string['check'] is
treated as $string[0], so it evaluates to a string with only the first
character of $string. Then it is checked, whether this string has a
character at position zero. As this is true, isset returns true.
You may consider using array_key_exists() instead of isset().
--
Christoph M. Becker
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Christoph Becker
2014-05-15 02:06:29 UTC
Permalink
Post by Rain Lee
I think the convert that cause the 'key' become 0 is ... not a good
idea. But my experience on PHP is so little, maybe there is some
reason for it that i never know.
I have to agree that this behavior is somewhat unexpected. However, it
seems to fit well to PHP's type juggling, which generally takes getting
used to. And of course you can get around this behavior by making sure
you have an array and not a string; consider making use of type hinting[1].
Post by Rain Lee
Don't know what's the opinion of those guys inside the PHP.
Me neither. You might consider filing a feature request[2] or asking on
php.internals[3].

[1] <http://www.php.net/manual/en/language.oop5.typehinting.php>
[2] <https://bugs.php.net/>
[3] <news://news.php.net/php.internals>
--
Christoph M. Becker
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Aziz Saleh
2014-05-15 02:12:43 UTC
Permalink
Post by Christoph Becker
Post by Rain Lee
I think the convert that cause the 'key' become 0 is ... not a good
idea. But my experience on PHP is so little, maybe there is some
reason for it that i never know.
I have to agree that this behavior is somewhat unexpected. However, it
seems to fit well to PHP's type juggling, which generally takes getting
used to. And of course you can get around this behavior by making sure
you have an array and not a string; consider making use of type hinting[1].
Post by Rain Lee
Don't know what's the opinion of those guys inside the PHP.
Me neither. You might consider filing a feature request[2] or asking on
php.internals[3].
[1] <http://www.php.net/manual/en/language.oop5.typehinting.php>
[2] <https://bugs.php.net/>
[3] <news://news.php.net/php.internals>
--
Christoph M. Becker
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Trying different versions of php give different results:

http://sandbox.onlinephpfunctions.com/

$string = 'this is a string';
var_dump($string['check']);

var_dump(isset($string['check']));
var_dump(isset($string['check'][0]));

Biggest change from 5.3 -> 5.5

No idea why this is happening, like Chris said php internals might be a
good place to ask.
Christoph Becker
2014-05-15 12:08:25 UTC
Permalink
Post by Aziz Saleh
http://sandbox.onlinephpfunctions.com/
$string = 'this is a string';
var_dump($string['check']);
var_dump(isset($string['check']));
var_dump(isset($string['check'][0]));
Biggest change from 5.3 -> 5.5
Good catch! I was not aware of this change. I have double-checked that
on <http://3v4l.org/5GGYm>, and apparently, the behavior has completely
turned around since PHP 5.4. The manual[1] notes:

| Non-numeric string offsets - e.g. $a['foo'] where $a is a string -
| now return false on isset() and true on empty(), and produce a
| E_WARNING if you try to use them. Offsets of types double, bool and
| null produce a E_NOTICE. Numeric strings (e.g. $a['2']) still work as
| before. Note that offsets like '12.3' and '5 foobar' are considered
| non-numeric and produce a E_WARNING, but are converted to 12 and 5
| respectively, for backward compatibility reasons. Note: Following
| code returns different result. $str='abc';var_dump(isset($str['x']));
| // false for PHP 5.4 or later, but true for 5.3 or less

I've also found a related (documentation) bug report:
<https://bugs.php.net/bug.php?id=61507>.

[1] <http://www.php.net/manual/en/migration54.incompatible.php>
--
Christoph M. Becker
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Jim Lucas
2014-05-14 16:27:23 UTC
Permalink
Post by \\R\\N
Greeting guys,
I got a problem on checking and getting a string with multi dim index (like
['blablabla']['blabla']). It confusing me, so I think I need to found an
answer to clear myself.
First of all, I known that is wrong to get something from a string using a
multi dim index or even a string index. I did it by mistakenly set a wrong
parameter. The parameter supposed to be array with string as index (That
will actually be a hashmap), but I setted a string on it.
As result, I got a warning raised: Illegal string offset.
It's normal since I use the string as index to attempt to getting something
from a string. But the strange thing is, I did the isset check before use
the index. It supposed to be hot pass the check, but it did.
https://gist.github.com/raincious/682ba152dbd74537e323#file-stringisset-php
The test 1 is what I used in my application, it checks if the array index is
$string = array(
'check' => 'yes',
); // Please ignore the variable name
But when the $string truly turned to a string, it become the source of my
question.
http://www.php.net/manual/en/function.isset.php says, "Checking non-numeric
offsets of strings now returns FALSE." since 5.4, and I using 5.5.
So the test 3 (isset($string['check']) one) running as expected, it returns
false. However, the test1 (isset($string['check'][0]) one) is unfortunatly
not, It actually returnning true.
I'm not a experter of PHP and I even need other people's help to read PHP
source code, but in the information from the document and the talking with
other people gives me some guts to guess the $string['check'][0] actually
will be converted into $string[(int)'check'][0] and then into $string[0][0],
so the test 1 can be pass. Is that right?
So, what I want to know is, why there has two kind of behaviour for isset?
Maybe it's better to let the isset($string['check'][0]) and
isset($string['check']) both return false?
What you are describing, and what is in your test script on github is
extremely confusing. I'm still not sure what you think you are trying to
accomplish with your tests.

Can you give us a real world example of what it is you are trying to do?
Post by \\R\\N
And sorry for my english, please ask if you confused by me.
Thank you,
R
--
Jim Lucas

http://www.cmsws.com/
http://www.cmsws.com/examples/
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Rain Lee
2014-05-15 00:55:19 UTC
Permalink
So, here is the TLDR;

$string = 'this is a string';

In PHP 5.5
isset($string['check']) === false
isset($string['check'][0]) === true

Why can't let
isset($string['check']) === false
isset($string['check'][0]) === false <--

?
Post by Jim Lucas
Post by \\R\\N
Greeting guys,
I got a problem on checking and getting a string with multi dim index (like
['blablabla']['blabla']). It confusing me, so I think I need to found an
answer to clear myself.
First of all, I known that is wrong to get something from a string using a
multi dim index or even a string index. I did it by mistakenly set a wrong
parameter. The parameter supposed to be array with string as index (That
will actually be a hashmap), but I setted a string on it.
As result, I got a warning raised: Illegal string offset.
It's normal since I use the string as index to attempt to getting something
from a string. But the strange thing is, I did the isset check before use
the index. It supposed to be hot pass the check, but it did.
https://gist.github.com/raincious/682ba152dbd74537e323#file-stringisset-php
The test 1 is what I used in my application, it checks if the array index is
$string = array(
'check' => 'yes',
); // Please ignore the variable name
But when the $string truly turned to a string, it become the source of my
question.
http://www.php.net/manual/en/function.isset.php says, "Checking non-numeric
offsets of strings now returns FALSE." since 5.4, and I using 5.5.
So the test 3 (isset($string['check']) one) running as expected, it returns
false. However, the test1 (isset($string['check'][0]) one) is unfortunatly
not, It actually returnning true.
I'm not a experter of PHP and I even need other people's help to read PHP
source code, but in the information from the document and the talking with
other people gives me some guts to guess the $string['check'][0] actually
will be converted into $string[(int)'check'][0] and then into
$string[0][0],
so the test 1 can be pass. Is that right?
So, what I want to know is, why there has two kind of behaviour for isset?
Maybe it's better to let the isset($string['check'][0]) and
isset($string['check']) both return false?
What you are describing, and what is in your test script on github is
extremely confusing. I'm still not sure what you think you are trying to
accomplish with your tests.
Can you give us a real world example of what it is you are trying to do?
Post by \\R\\N
And sorry for my english, please ask if you confused by me.
Thank you,
R
--
Jim Lucas
http://www.cmsws.com/
http://www.cmsws.com/examples/
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Aziz Saleh
2014-05-15 01:07:33 UTC
Permalink
Post by Rain Lee
So, here is the TLDR;
$string = 'this is a string';
In PHP 5.5
isset($string['check']) === false
isset($string['check'][0]) === true
Why can't let
isset($string['check']) === false
isset($string['check'][0]) === false <--
?
Post by Jim Lucas
Post by \\R\\N
Greeting guys,
I got a problem on checking and getting a string with multi dim index (like
['blablabla']['blabla']). It confusing me, so I think I need to found an
answer to clear myself.
First of all, I known that is wrong to get something from a string
using a
Post by Jim Lucas
Post by \\R\\N
multi dim index or even a string index. I did it by mistakenly set a
wrong
Post by Jim Lucas
Post by \\R\\N
parameter. The parameter supposed to be array with string as index (That
will actually be a hashmap), but I setted a string on it.
As result, I got a warning raised: Illegal string offset.
It's normal since I use the string as index to attempt to getting something
from a string. But the strange thing is, I did the isset check before
use
Post by Jim Lucas
Post by \\R\\N
the index. It supposed to be hot pass the check, but it did.
https://gist.github.com/raincious/682ba152dbd74537e323#file-stringisset-php
Post by Jim Lucas
Post by \\R\\N
The test 1 is what I used in my application, it checks if the array
index
Post by Jim Lucas
Post by \\R\\N
is
set and not empty in same time. A valid param for it should be like
$string = array(
'check' => 'yes',
); // Please ignore the variable name
But when the $string truly turned to a string, it become the source of
my
Post by Jim Lucas
Post by \\R\\N
question.
http://www.php.net/manual/en/function.isset.php says, "Checking non-numeric
offsets of strings now returns FALSE." since 5.4, and I using 5.5.
So the test 3 (isset($string['check']) one) running as expected, it returns
false. However, the test1 (isset($string['check'][0]) one) is
unfortunatly
Post by Jim Lucas
Post by \\R\\N
not, It actually returnning true.
I'm not a experter of PHP and I even need other people's help to read
PHP
Post by Jim Lucas
Post by \\R\\N
source code, but in the information from the document and the talking
with
Post by Jim Lucas
Post by \\R\\N
other people gives me some guts to guess the $string['check'][0]
actually
Post by Jim Lucas
Post by \\R\\N
will be converted into $string[(int)'check'][0] and then into $string[0][0],
so the test 1 can be pass. Is that right?
So, what I want to know is, why there has two kind of behaviour for
isset?
Post by Jim Lucas
Post by \\R\\N
Maybe it's better to let the isset($string['check'][0]) and
isset($string['check']) both return false?
What you are describing, and what is in your test script on github is
extremely confusing. I'm still not sure what you think you are trying to
accomplish with your tests.
Can you give us a real world example of what it is you are trying to do?
Post by \\R\\N
And sorry for my english, please ask if you confused by me.
Thank you,
R
--
Jim Lucas
http://www.cmsws.com/
http://www.cmsws.com/examples/
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
I think you switched the two:

isset($string['check']) === true
isset($string['check'][0]) === false

'check' is automatically converted to an int by PHP (since the array is
numeric) which gives you $string[0] which is set. However, if you try ding
$string[0][0] ($string['check'][0]) it will give you false since it does
not exist.

PHP is pretty flexible when it comes to using ints as strings and vice
verse, you just need to know you are using them correctly.

Also use var_dump() when doing checks to give you a better idea what PHP is
doing behind the scenes.

Aziz
Rain Lee
2014-05-15 01:34:02 UTC
Permalink
Hi Aziz,

Problem is i didn't switch that.

The test i mentioned here: http://news.php.net/php.general/323297
showing this result with PHP 5.5.
Post by Aziz Saleh
Post by Rain Lee
So, here is the TLDR;
$string = 'this is a string';
In PHP 5.5
isset($string['check']) === false
isset($string['check'][0]) === true
Why can't let
isset($string['check']) === false
isset($string['check'][0]) === false <--
?
Post by Jim Lucas
Post by \\R\\N
Greeting guys,
I got a problem on checking and getting a string with multi dim index (like
['blablabla']['blabla']). It confusing me, so I think I need to found an
answer to clear myself.
First of all, I known that is wrong to get something from a string using a
multi dim index or even a string index. I did it by mistakenly set a wrong
parameter. The parameter supposed to be array with string as index (That
will actually be a hashmap), but I setted a string on it.
As result, I got a warning raised: Illegal string offset.
It's normal since I use the string as index to attempt to getting something
from a string. But the strange thing is, I did the isset check before use
the index. It supposed to be hot pass the check, but it did.
https://gist.github.com/raincious/682ba152dbd74537e323#file-stringisset-php
The test 1 is what I used in my application, it checks if the array
index
is
$string = array(
'check' => 'yes',
); // Please ignore the variable name
But when the $string truly turned to a string, it become the source of my
question.
http://www.php.net/manual/en/function.isset.php says, "Checking non-numeric
offsets of strings now returns FALSE." since 5.4, and I using 5.5.
So the test 3 (isset($string['check']) one) running as expected, it returns
false. However, the test1 (isset($string['check'][0]) one) is unfortunatly
not, It actually returnning true.
I'm not a experter of PHP and I even need other people's help to read PHP
source code, but in the information from the document and the talking with
other people gives me some guts to guess the $string['check'][0] actually
will be converted into $string[(int)'check'][0] and then into $string[0][0],
so the test 1 can be pass. Is that right?
So, what I want to know is, why there has two kind of behaviour for isset?
Maybe it's better to let the isset($string['check'][0]) and
isset($string['check']) both return false?
What you are describing, and what is in your test script on github is
extremely confusing. I'm still not sure what you think you are trying to
accomplish with your tests.
Can you give us a real world example of what it is you are trying to do?
Post by \\R\\N
And sorry for my english, please ask if you confused by me.
Thank you,
R
--
Jim Lucas
http://www.cmsws.com/
http://www.cmsws.com/examples/
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
isset($string['check']) === true
isset($string['check'][0]) === false
'check' is automatically converted to an int by PHP (since the array is
numeric) which gives you $string[0] which is set. However, if you try ding
$string[0][0] ($string['check'][0]) it will give you false since it does not
exist.
PHP is pretty flexible when it comes to using ints as strings and vice
verse, you just need to know you are using them correctly.
Also use var_dump() when doing checks to give you a better idea what PHP is
doing behind the scenes.
Aziz
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Ford, Mike
2014-05-15 16:39:32 UTC
Permalink
-----Original Message-----
Sent: 15 May 2014 01:55
To: Jim Lucas
Subject: Re: [PHP] A little confusing thing on (mistakenly) geting a
offset from string with multi dim index.
So, here is the TLDR;
$string = 'this is a string';
In PHP 5.5
isset($string['check']) === false
Yes, because isset is specifically defined (nowadays) to reject string
Offsets on a string.
isset($string['check'][0]) === true
This is correct because the isset is only checking the final index -
it's not doing any checks on 'check', so the normal PHP rules of
string->integer conversion apply, and you get a zero. (If you don't
know what the "normal rules" are, see http://ow.ly/wT2t0).

So, $string['check'] is effectively $string[0], which is "t"; so
$string['check'][0] is $string[0][0], which is set and evaluates
to "t".

To check that all the indexes work, you will need to do

if (isset($string['check']) && isset($string['check'][0]))

Or even

if (isset($string['check'], $string['check'][0]))

which has the same effect.


Cheers!

Mike
--
Mike Ford,
Electronic Information Developer, Libraries and Learning Innovation,
403a Leslie Silver Building, City Campus, Leeds Metropolitan University,
Woodhouse Lane, LEEDS, LS1 3ES, United Kingdom
E: ***@leedsmet.ac.uk T: +44 113 812 4730







From 22 September 2014 Leeds Metropolitan University will become Leeds Beckett University.
Find out more at http://www.leedsbeckett.ac.uk
To view the terms under which this email is distributed, please go to:-
http://www.leedsmet.ac.uk/email-disclaimer.htm
\\R\\N
2014-05-16 01:23:40 UTC
Permalink
Thank you Mike.

I post this thread just because I surprised by this behavior (Not because I
got problem on it, so there is no real world example, just the test itself).

In simple say, I don't think the conversion is good idea. I mean, if
isset($string['check']) and isset($string['check'][0]) can be both false,
that will be better for understanding. (So I post my complain and looking
for chances of change)

I did post in php.internals, but no response yet, maybe thats because my
english too poor to explain this clearly or guys inside php think that is
fine.

isset($string['check'], $string['check'][0]) is good, I will use it when I
need.
-----Original Message-----
Sent: 15 May 2014 01:55
To: Jim Lucas
Subject: Re: [PHP] A little confusing thing on (mistakenly) geting a
offset from string with multi dim index.
So, here is the TLDR;
$string = 'this is a string';
In PHP 5.5
isset($string['check']) === false
Yes, because isset is specifically defined (nowadays) to reject string
Offsets on a string.
isset($string['check'][0]) === true
This is correct because the isset is only checking the final index -
it's not doing any checks on 'check', so the normal PHP rules of
string->integer conversion apply, and you get a zero. (If you don't
know what the "normal rules" are, see http://ow.ly/wT2t0).

So, $string['check'] is effectively $string[0], which is "t"; so
$string['check'][0] is $string[0][0], which is set and evaluates
to "t".

To check that all the indexes work, you will need to do

if (isset($string['check']) && isset($string['check'][0]))

Or even

if (isset($string['check'], $string['check'][0]))

which has the same effect.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Jim Lucas
2014-05-15 15:46:51 UTC
Permalink
Post by Rain Lee
So, here is the TLDR;
$string = 'this is a string';
In PHP 5.5
isset($string['check']) === false
isset($string['check'][0]) === true
Why can't let
isset($string['check']) === false
isset($string['check'][0]) === false <--
?
I can see WHAT you are doing and WHAT the results are, but I don't understand
WHY would you ever do this?

You defined $string with a string of characters. But you are trying to use
$string as an array. This hits me as completely wrong.

I wanted to see an example of you doing this in a complete script. Because I
cannot envision why you would ever end up doing this. And I wanted to see how
you got to this as a solution.
--
Jim Lucas

http://www.cmsws.com/
http://www.cmsws.com/examples/
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
\\R\\N
2014-05-15 16:26:58 UTC
Permalink
Please stop talking about this usage, I found this problem by a mistakely as
I said. My self not made any mistake on this, because I do test.
Post by Rain Lee
So, here is the TLDR;
$string = 'this is a string';
In PHP 5.5
isset($string['check']) === false
isset($string['check'][0]) === true
Why can't let
isset($string['check']) === false
isset($string['check'][0]) === false <--
?
I can see WHAT you are doing and WHAT the results are, but I don't
understand
WHY would you ever do this?

You defined $string with a string of characters. But you are trying to use
$string as an array. This hits me as completely wrong.

I wanted to see an example of you doing this in a complete script. Because
I
cannot envision why you would ever end up doing this. And I wanted to see
how
you got to this as a solution.
--
Jim Lucas

http://www.cmsws.com/
http://www.cmsws.com/examples/
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Ford, Mike
2014-05-15 16:26:42 UTC
Permalink
-----Original Message-----
Sent: 15 May 2014 16:47
Subject: Re: [PHP] A little confusing thing on (mistakenly) geting a
offset from string with multi dim index.
Post by Rain Lee
So, here is the TLDR;
$string = 'this is a string';
In PHP 5.5
isset($string['check']) === false
isset($string['check'][0]) === true
Why can't let
isset($string['check']) === false
isset($string['check'][0]) === false <--
?
I can see WHAT you are doing and WHAT the results are, but I don't understand
WHY would you ever do this?
You defined $string with a string of characters. But you are trying to use
$string as an array. This hits me as completely wrong.
That's a perfectly normal PHP idiom to get the nth character of the
string, I do it all over the place - $string[$n] is equivalent to
substr($string, $n, 1);


Cheers!

Mike
--
Mike Ford,
Electronic Information Developer, Libraries and Learning Innovation,
403a Leslie Silver Building, City Campus, Leeds Metropolitan University,
Woodhouse Lane, LEEDS, LS1 3ES, United Kingdom
E: ***@leedsmet.ac.uk T: +44 113 812 4730






From 22 September 2014 Leeds Metropolitan University will become Leeds Beckett University.
Find out more at http://www.leedsbeckett.ac.uk
To view the terms under which this email is distributed, please go to:-
http://www.leeds
Jim Lucas
2014-05-15 16:45:29 UTC
Permalink
Post by Ford, Mike
-----Original Message-----
Sent: 15 May 2014 16:47
Subject: Re: [PHP] A little confusing thing on (mistakenly) geting a
offset from string with multi dim index.
Post by Rain Lee
So, here is the TLDR;
$string = 'this is a string';
In PHP 5.5
isset($string['check']) === false
isset($string['check'][0]) === true
Why can't let
isset($string['check']) === false
isset($string['check'][0]) === false <--
?
I can see WHAT you are doing and WHAT the results are, but I don't understand
WHY would you ever do this?
You defined $string with a string of characters. But you are trying to use
$string as an array. This hits me as completely wrong.
That's a perfectly normal PHP idiom to get the nth character of the
string, I do it all over the place - $string[$n] is equivalent to
substr($string, $n, 1);
You are pulling data from a string using a method that is perfectly valid.

He is testing for something. Not the same thing.
Post by Ford, Mike
Cheers!
Mike
--
Mike Ford,
Electronic Information Developer, Libraries and Learning Innovation,
403a Leslie Silver Building, City Campus, Leeds Metropolitan University,
Woodhouse Lane, LEEDS, LS1 3ES, United Kingdom
From 22 September 2014 Leeds Metropolitan University will become Leeds Beckett University.
Find out more at http://www.leedsbeckett.ac.uk
To view the terms under which this email is distributed, please go to:-
http://www.leedsmet.ac.uk/email-disclaimer.htm
--
Jim Lucas

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