Strict Standards

I am testing the following on PHP Version 5.2.12.

code1

$varText='I Like the boy';
$before=array_shift(explode('ik', $varText));
echo $before;

The code1 above works fine.
However,

code2

declare(strict_types=1);
error_reporting(-1);

$varText='I Like the boy';
$before=array_shift(explode('ik', $varText));
echo $before;

The code2 above produces the following

Although I change “ik” to a variable like the code3 below, Strick Standard still produces

declare(strict_types=1);
error_reporting(-1);

$varText='I Like the boy';
$delimiter='ik';
$before=array_shift(explode($delimiter, $varText));
echo $before;

How can I make it clear?

array_shift is complaining because it’s not being handed a variable reference, it’s being handed a literal array.

2 Likes

Try expanding the line giving the error:

$tmp = explode($delimiter, $varText);
$before=array_shift( $tmp );

Also if you check the PHP online manual it will show the expected type of variables for the two functions.

I wasn’t aware strict types was available in versions before PHP 7.

the error generated isnt actually a strict-types error; it’s a E_NOTICE level event thrown by array_shift regardless of typing.

<?php
error_reporting(-1);

$varText='I Like the boy';
$arr = array_shift(explode('ik', $varText));
?>

Notice: Only variables should be passed by reference in D:\xampp\htdocs\s\s13.php on line 5

1 Like

And because I anticipate query as to why: PHP is flagging this as a potential problem because array_shifting a literal array orphans the rest of the array: In other words, while $arr in the above statement will contain the string "I L", the other half of the array (['e the boy']) becomes non-referable.

1 Like

It wasn’t. I’m assuming that’s a typo in the OP.

1 Like

I did wonder why someone was testing in 5.2.12.

2 Likes

WHY? That is hundreds of releases behind and reached end of life long, long ago.

Hundreds? Do we know what exaggeration means?

Apparently you cant count. That would be 301 releases, so yes, HUNDREDS of releases behind.

7.3.11
7.3.10
7.3.9
7.3.8
7.3.7
7.3.6
7.3.5
7.3.4
7.3.3
7.3.2
7.3.1
7.3.0
7.2.24
7.2.23
7.2.22
7.2.21
7.2.20
7.2.19
7.2.18
7.2.17
7.2.16
7.2.15
7.2.14
7.2.13
7.2.12
7.2.11
7.2.10
7.2.9
7.2.8
7.2.7
7.2.6
7.2.5
7.2.4
7.2.3
7.2.2
7.2.1
7.2.0
7.1.33
7.1.32 Released: 29 Aug 2019
7.3.10 Released: 26 Sep 2019
7.2.23 Released: 26 Sep 2019
7.2.22 Released: 29 Aug 2019
7.3.9  Released: 29 Aug 2019
7.1.31 Released: 01 Aug 2019
7.2.2  Released: 01 Aug 2019
7.3.8  Released: 01 Aug 2019
7.1.30 Released: 30 May 2019
7.2.20 Released: 04 Jul 2019
7.3.7  Released: 04 Jul 2019
7.2.19 Released: 30 May 2019
7.3.6  Released: 30 May 2019
7.1.29 Released: 02 May 2019
7.2.18 Released: 30 May 2019
7.3.5  Released: 02 May 2019
7.1.28 Released: 02 May 2019
7.2.17 Released: 02 May 2019
7.3.4  Released: 04 Apr 2019
7.1.27 Released: 07 Mar 2019
7.2.16 Released: 04 Apr 2019
7.3.3  Released: 07 Mar 2019
7.1.26 Released: 10 Jan 2019
7.2.15 Released: 07 Mar 2019
7.3.2  Released: 07 Feb 2019
7.2.14 Released: 07 Feb 2019
7.3.1  Released: 10 Jan 2019
7.0.33 Released: 10 Jan 2019
7.1.25 Released: 06 Dec 2018
7.3.0  Released: 06 Dec 2018
7.2.13 Released: 06 Dec 2018
7.0.32 Released: 13 Sep 2018
7.1.24 Released: 08 Nov 2018
7.2.12 Released: 08 Nov 2018
7.1.23 Released: 11 Oct 2018
7.2.11 Released: 11 Oct 2018
7.1.22 Released: 13 Sep 2018
7.2.10 Released: 13 Sep 2018
7.1.21 Released: 13 Sep 2018
7.0.31 Released: 19 Jul 2018
7.2.9  Released: 16 Aug 2018
7.1.20 Released: 16 Aug 2018
7.2.8  Released: 19 Jul 2018
7.1.19 Released: 21 Jun 2018
7.0.30 Released: 26 Apr 2018
7.2.7  Released: 21 Jun 2018
7.1.18 Released: 24 May 2018
7.2.6  Released: 24 May 2018
7.1.17 Released: 26 Apr 2018
7.2.5  Released: 26 Apr 2018
7.1.16 Released: 29 Mar 2018
7.0.29 Released: 29 Mar 2018
7.2.4  Released: 29 Mar 2018
7.1.15 Released: 1 Mar 2018
7.2.3  Released: 1 Mar 2018
7.0.28 Released: 01 Mar 2018
7.1.14 Released: 1 Feb 2018
7.2.2  Released: 1 Feb 2018
7.0.27 Released: 04 Jan 2018
7.2.1  Released: 4 Jan 2018
7.1.13 Released: 4 Jan 2018
7.2.0  Released: 30 Nov 2017
7.1.12 Released: 23 Nov 2017
7.0.26 Released: 23 Nov 2017
7.1.11 Released: 26 Oct 2017
7.0.25 Released: 26 Oct 2017
7.1.10 Released: 28 Sep 2017
7.0.24 Released: 28 Sep 2017
7.1.9  Released: 31 Aug 2017
7.0.23 Released: 31 Aug 2017
7.1.8  Released: 03 Aug 2017
7.0.22 Released: 03 Aug 2017
7.1.7  Released: 06 Jul 2017
7.0.21 Released: 06 Jul 2017
7.1.6  Released: 08 Jun 2017
7.0.20 Released: 08 Jun 2017
7.1.5  Released: 11 May 2017
7.0.19 Released: 11 May 2017
7.1.4  Released: 13 Apr 2017
7.0.18 Released: 13 Apr 2017
7.1.3  Released: 16 Mar 2017
7.0.17 Released: 30 Mar 2017
7.1.2  Released: 16 Feb 2017
7.0.16 Released: 16 Feb 2017
7.1.1  Released: 19 Jan 2017
7.0.15 Released: 19 Jan 2017
7.0.14 Released: 08 Dec 2016
7.1.0  Released: 01 Dec 2016
7.0.13 Released: 10 Nov 2016
7.0.12 Released: 13 Oct 2016
7.0.11 Released: 15 Sep 2016
7.0.10 Released: 18 Aug 2016
7.0.9  Released: 21 Jul 2016
7.0.8  Released: 23 Jun 2016
7.0.7  Released: 26 May 2016
7.0.6  Released: 28 Apr 2016
7.0.5  Released: 31 Mar 2016
7.0.4  Released: 03 Mar 2016
7.0.3  Released: 04 Feb 2016
7.0.2  Released: 07 Jan 2015
7.0.1  Released: 17 Dec 2015
7.0.0  Released: 03 Dec 2015
5.6.40 Released: 10 Jan 2019
5.6.39 Released: 06 Dec 2018
5.6.38 Released: 13 Sep 2018
5.6.37 Released: 19 Jul 2018
5.6.36 Released: 26 Apr 2018
5.6.35 Released: 29 Mar 2018
5.6.34 Released: 01 Mar 2018
5.6.33 Released: 04 Jan 2018
5.6.32 Released: 26 Oct 2017
5.6.31 Released: 06 Jul 2017
5.6.30 Released: 19 Jan 2017
5.6.29 Released: 08 Dec 2016
5.6.28 Released: 10 Nov 2016
5.6.27 Released: 13 Oct 2016
5.6.26 Released: 15 Sep 2016
5.6.25 Released: 18 Aug 2016
5.6.24 Released: 21 Jul 2016
5.5.38 Released: 21 Jul 2016
5.6.23 Released: 23 Jun 2016
5.5.37 Released: 23 Jun 2016
5.5.36 Released: 26 May 2016
5.6.22 Released: 26 May 2016
5.6.21 Released: 28 Apr 2016
5.5.35 Released: 31 Mar 2016
5.6.20 Released: 31 Marc 2016
5.5.34 Released: 31 Mar 2016
5.6.19 Released: 03 Marc 2016
5.5.33 Released: 03 Mar 2016
5.6.18 Released: 04 Feb 2016
5.5.32 Released: 04 Feb 2016
5.6.17 Released: 07 Jan 2016
5.5.31 Released: 07 Jan 2016
5.6.16 Released: 26 Nov 2015
5.5.30 Released: 01 Oct 2015
5.6.15 Released: 29 Oct 2015
5.6.14 Released: 01 Oct 2015
5.6.13 Released: 03 Sep 2015
5.5.29 Released: 03 Sep 2015
5.5.28 Released: 06 Aug 2015
5.6.12 Released: 06 Aug 2015
5.6.11
5.5.27
5.6.10
5.5.26
5.6.9
5.5.25
5.6.8
5.5.24
5.6.7
5.5.23
5.6.6
5.5.22
5.6.5
5.5.21
5.6.4
5.5.20
5.6.3
5.5.19
5.6.2
5.5.18
5.6.1
5.5.17
5.6.0
5.5.16
5.5.15
5.5.14
5.5.13
5.5.12
5.5.11
5.5.10
5.5.9
5.5.8
5.5.7
5.5.6
5.5.5
5.5.4
5.5.3
5.5.2
5.5.1
5.5.0
5.4.45
5.4.44
5.4.43
5.4.42
5.4.41
5.4.40
5.4.39
5.4.38
5.4.37
5.4.36
5.4.35
5.4.34
5.4.33
5.4.32
5.4.31
5.4.30
5.4.29
5.4.28
5.4.27
5.4.26
5.4.25
5.4.24
5.4.23
5.4.22
5.4.21
5.4.20
5.4.19
5.4.18
5.4.17
5.4.16
5.4.15
5.4.14
5.4.13
5.4.12
5.4.11
5.4.10
5.4.9
5.4.8
5.4.7
5.4.6
5.4.5
5.4.4
5.4.3
5.4.2
5.4.1
5.4.0
5.3.29
5.3.28
5.3.27
5.3.26
5.3.25
5.3.24
5.3.23
5.3.22
5.3.21
5.3.20
5.3.19
5.3.18
5.3.17
5.3.16
5.3.15
5.3.14
5.3.13
5.3.12
5.3.11
5.3.10
5.3.9
5.3.8
5.3.7
5.3.6
5.3.5
5.3.4
5.2.17
5.2.16
5.2.15
5.3.3
5.2.14
5.3.2
5.2.13
5.3.1
5.2.12 

I have an old project in PHP5…
I have a new project in PHP7.

I am on the way of immigration from the old project to the new project.

1 Like

Glad to hear that. Sometimes people refuse to get current.

So if you are going to refactor the old app instead of doing a re-write, turn up error reporting full blast in php7 and try and run your code. Php will be more than happy to tell you what is wrong. Also, if you have a good IDE that will also tell you. I know PhpStorm will let you know of all the issues it finds. I would also recommend you run no less that Php 7.3. There have been many changes in the 7.x branch and the early 7 versions are already end of life.

We will be happy to help you with your transition.

Eh. Couple of those are double-tracked development (7.1.1 and 7.0.15, for example), but yeah… good to see that this is being done in effort of updating to the latest version.

May not need to clear all the E_NOTICE level stuff, but it can’t hurt.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.