php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #80212 Decrement operator doesn't work as stated in the manual
Submitted: 2020-10-10 10:20 UTC Modified: 2020-10-10 10:42 UTC
From: g dot a dot stamoulis at gmail dot com Assigned:
Status: Open Package: Strings related
PHP Version: 7.4.11 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
50 - 19 = ?
Subscribe to this entry?

 
 [2020-10-10 10:20 UTC] g dot a dot stamoulis at gmail dot com
Description:
------------
Strings can be incremented by the ++ operator but they don't get decremented by the -- operator. This is seems inconsistent and it is also not documented in the manual.  

Test script:
---------------
<?php
$test = 'abc12';

// increment works as expected
echo(++$test . "\n");
echo(++$test . "\n");
echo(++$test . "\n");

// decrement fails
echo(--$test . "\n");
echo(--$test . "\n");
echo(--$test . "\n");

Expected result:
----------------
abc13
abc14
abc15
abc14
abc13
abc12


Actual result:
--------------
abc13
abc14
abc15
abc15
abc15
abc15

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-10-10 10:42 UTC] cmb@php.net
-Type: Bug +Type: Documentation Problem
 [2020-10-10 10:42 UTC] cmb@php.net
The manual already states[1]:

| Note that character variables can be incremented but not
| decremented […]

Maybe this important note should be more prominent.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 01:01:31 2024 UTC