Home > Archive > PHP Programming > November 2005 > No more access to characters in strings in PHP 6?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
No more access to characters in strings in PHP 6?
|
|
| Chung Leong 2005-11-19, 3:56 am |
| Just saw a message in pl.comp.lang.php, which states that the following
message has appeared in the PHP CVS snapshot:
Usage of {} to access string offsets is deprecated and will be removed
in PHP 6
What do you think of that?
| |
| Andy Hassall 2005-11-19, 7:55 am |
| On 18 Nov 2005 17:40:34 -0800, "Chung Leong" <chernyshevsky@hotmail.com> wrote:
>Just saw a message in pl.comp.lang.php, which states that the following
>message has appeared in the PHP CVS snapshot:
>
>Usage of {} to access string offsets is deprecated and will be removed
>in PHP 6
>
>What do you think of that?
So, both [] and {} access is deprecated?
http://uk.php.net/string
"String access and modification by character
Characters within strings may be accessed and modified by specifying the
zero-based offset of the desired character after the string in curly braces.
Note: For backwards compatibility, you can still use array-brackets for the
same purpose. However, this syntax is deprecated as of PHP 4. "
Or have they changed their minds and the (more sensible) array-like access is
back as the preferred method?
--
Andy Hassall :: andy@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
| |
| Chung Leong 2005-11-20, 3:56 am |
| Ewoud Dronkert wrote:
> Chung Leong wrote:
>
> That would be a shocker, unless they intend to go back to array-type
> indexing with square brackets (deprecated as of v4). I must admit I don't
> use it very often, but it's kind of a standard feature for any language,
> isn't it? It would be a drag to always have to use substr(,,1).
What I worry about is that they'll make text string a closed structure.
If strings are to be encoded in UTF-8 internally, then they might need
to remove character-level access. I must say I really dislike the
direction PHP is heading.
| |
| Oliver Saunders 2005-11-25, 6:57 pm |
| no no no.
$str{} is deprecated
$str[] was deprecated but is now undeprecated
in fact $str[] will have more power than ever before:
<quote from="minutes php developers meeting"
src="http://www.php.net/~derick/meeting-notes.html#cleanup-for-vs">
1.
We will undeprecate [] for accessing characters in strings.
2.
{} will be deprecated in PHP 5.1.0 with an E_STRICT and removed
in PHP 6.
3.
For both strings and arrays, the [] operator will support
substr()/array_slice() functionality:
* [2,3] is elements (or characters) 2, 3, 4
* [2,] is elements (or characters) 2 to the end
* [,2] is elements (or characters) 0, 1, 2
* [,-2] is from the start until the last two elements in
the array/string
* [-3,2] this is the same as substr and array_slice()
* [,] doesn't work on the left side of an equation.
With these rules, the behaviour for strings will be:
* $str = "foo"; $str[] = "d"; we modify to make a
concatenation.
* $str = "fo"; $str[] = "od"; will concatenate to "food"
* $str = ""; $str[] = "d"; should become the string "d",
this should become an e_strict in 5.1.1. We need to check how common
this is first.
</quote>
| |
| Oli Filth 2005-11-25, 9:55 pm |
| Oliver Saunders said the following on 25/11/2005 23:57:
> no no no.
>
> $str{} is deprecated
> $str[] was deprecated but is now undeprecated
God bless the PHP "design" committee - deprecate something, introduce a
new syntax, then deprecate the new syntax and re-introduce the old
syntax. A real step forward for the "keep the language simple" principle
that they so fervently claim to adhere to.
It sometimes seems that there's no long-term vision at all when it comes
to the development of PHP.
> http://www.php.net/~derick/meeting-notes.html
There's several things described in that document which, IMO, show that
the developers are just trying to pander to novices <insert flame-war
here> and oversimplify the language by adding "features" which make
certain things superficially easier to do, but will actually end up
leading to bad coding practices in the long-run. i.e.
* The "pseudo" goto
* Adding a constructor to interface definitions - that literally makes
no sense at all.
* Late static binding - no no no, that will make people assume that
polymorphism of statics makes some kind of sense, and that it's a
sensible idea.
However, I can only applaud the plan for the removal of magic_quotes and
register_globals. :)
--
Oli
| |
| Oliver Saunders 2005-11-25, 9:55 pm |
| > * Adding a constructor to interface definitions - that literally makes no sense at all.
I never did really get the point of defining interfaces. Care to
enlighten me Oli?
| |
| Geoff Berrow 2005-11-26, 7:55 am |
| Message-ID: <8rWdnQT4IpqZOBreRVnyvQ@pipex.net> from Oliver Saunders
contained the following:
>$str{} is deprecated
>$str[] was deprecated but is now undeprecated
Crazy. I always liked the idea of keeping array elements and string
elements separate - with novices having a hard enough time understanding
arrays as it is, any degree of separation is a good thing.
I foresee more furrowed brows in my classroom.
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
| |
| Oli Filth 2005-11-26, 7:55 am |
| Oliver Saunders said the following on 26/11/2005 03:10:
>
>
> I never did really get the point of defining interfaces. Care to
> enlighten me Oli?
Interfaces are a kind of substitute for multiple inheritance.
Whereas traditional inheritance relates classes that are sub-classes
(i.e. more specific instances) of a base class, interfaces allow
otherwise unrelated classes to expose the same specific set of behaviours.
A good example might be an iterator; e.g.:
interface Iterator
{
public function next();
public function previous();
public function rewind();
}
class Kennel implements Iterator
{
private $dogs = array("Rex", "Fido", "Boxer");
// lots of kennel-related functions here
public function next()
{
// return next dog
}
public function previous()
{
// return previous dog
}
public function rewind()
{
// go back to start of dog list
}
}
class DataPacket implements Iterator
{
private $data = "FF:32:5C:39:01:00:A6";
// lots of packet-related functions here
public function next()
{
// return next byte
}
public function previous()
{
// return previous byte
}
public function rewind()
{
// go back to first byte in packet
}
}
Now DataPacket and Kennel objects can both be passed to any function
expecting an Iterator. The same effect could be achieved by defining a
common base class and extending Kennel and DataPacket from that, but
that wouldn't make much sense because they have nothing in common
semantically.
From a practical point of view, if DataPacket and Kennel had been
derived from a common base class, that would put severe limitations on
any other inheritance relationships, e.g. if you had wanted Kennel to be
a sub-class of Building, then you'd be screwed.
--
Oli
| |
| Jerry Stuckle 2005-11-26, 6:56 pm |
| Geoff Berrow wrote:
> Message-ID: <8rWdnQT4IpqZOBreRVnyvQ@pipex.net> from Oliver Saunders
> contained the following:
>
>
>
>
> Crazy. I always liked the idea of keeping array elements and string
> elements separate - with novices having a hard enough time understanding
> arrays as it is, any degree of separation is a good thing.
>
> I foresee more furrowed brows in my classroom.
>
Geoff,
I think I'll have just the opposite effect. Basically it's handing a
string as an array of char, similar to C and C++.
Using the {} syntax has been quite confusing to my PHP students - why
have a special syntax just for strings? Whereas the [] syntax of C and
C++ has made understanding both strings and arrays easier for those
students.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
| |
| Geoff Berrow 2005-11-26, 6:56 pm |
| Message-ID: < ALKdnfdGkf3xHhXenZ2dnUVZ_t2dnZ2d@comcast
.com> from Jerry
Stuckle contained the following:
>
>Geoff,
>
>I think I'll have just the opposite effect. Basically it's handing a
>string as an array of char, similar to C and C++.
Well I suppose that's got to be a good thing. OK, I'll reserve
judgement.
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
|
|
|
|
|