WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 3 years ago

#13900 closed defect (bug) (fixed)

Curly Brackets String Index-Based-Access Deprecated

Reported by: hakre Owned by:
Milestone: 3.1 Priority: normal
Severity: normal Version: 3.0
Component: General Keywords: has-patch
Focuses: Cc:

Description

From the PHP Manual:

Note: String s [!sic] may also be accessed using braces, as in $str{42}, for the same purpose. However, this syntax is deprecated as of PHP 5.3.0. Use square brackets instead, such as $str[42].

It is recommended to replace it using square brackets ([,])

(Informative: I know at least that it has been warned about to use that since a longer time. It is a very old syntax and you find it often in outdated code, even before PHP 5.3.)

Attachments (1)

13900.patch (15.3 KB) - added by hakre 4 years ago.

Download all attachments as: .zip

Change History (8)

hakre4 years ago

comment:1 hakre4 years ago

  • Summary changed from Curly Braces String Index-Based-Access Deprecated to Curly Brackets String Index-Based-Access Deprecated

comment:2 nacin4 years ago

  • Milestone changed from 3.0.1 to 3.1

No need to handle this in a maintenance release, let's keep this clear. Many also apply diffs of maintenance releases and this is just a slew of code hunks that are trivial, so it's one less piece of noise by leaving it out.

Moving to 3.1.

comment:3 hakre4 years ago

Don't feel offended or distracted Nacin, I just did not wanted to judge about that before 3.0 is actually out and feedback to base a decision on is available. More and more users are using 5.3 these days and taking care of deprecated stuff looks like maintenance to me. But you do not need to share that opinion, I just write it here to explain why I suggested that 3.0.1 milestone.

comment:4 nacin4 years ago

I have no problem with the patch, but it's too late for 3.0. In fact I was reading PHP developer meeting minutes the other day and saw the curly bracket thing and made a mental note to search core for them, so I appreciate the patch.

It is indeed maintenance, good maintenance, but it doesn't meet our own definition of what a maintenance release is.

At the moment, we take care of deprecated stuff by silencing E_DEPRECATED. :-)

comment:5 hakre4 years ago

Ah good to see you're with me on this one. I stumbled over it about three weeks ago while in a look for something else and noted to fix it for this week. I think it even has some value for other projects and wrote a report about that: http://hakre.wordpress.com/2010/06/15/php-curly-brackets-substring-access/. It shows how I did it.

comment:6 nacin3 years ago

  • Milestone changed from Awaiting Triage to 3.1

Did PHP core undeprecate it? Looks like it.

"Note: Strings may also be accessed using braces, as in $str{42}, for the same purpose."

I'm finding the 5.3.0 reference become 6.0 on a mirror, but that's no longer there either.

I'm still fine with the patch, we should make it our coding standard. Incoming.

comment:7 nacin3 years ago

  • Resolution set to fixed
  • Status changed from new to closed

(In [16340]) Use square brackets instead of braces for string access. props hakre, fixes #13900.

Note: See TracTickets for help on using tickets.