Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #18386

value returned instead change the value of the variable

From alex <1j9448a02@lnx159sneakemail.com.invalid>
Newsgroups comp.lang.php
Subject value returned instead change the value of the variable
Date 2020-10-16 13:23 +0200
Organization Aioe.org NNTP Server
Message-ID <rmbvqm$lnh$1@gioia.aioe.org> (permalink)

Show all headers | View raw


// DESIGN 1
echo "It doesn't work (return 1 vs array), but I like 'DESIGN 1' ";
$arr = [1, 2];
print_r(
     array_shift($arr)
);

// DESIGN 2
echo "It works, but I don't like 'DESIGN 2': ";
$arr = [1, 2];
array_shift($arr);
print_r(
     $arr
);

Output:

It doesn't work (return 1 vs array), but I like 'DESIGN 1': 1

It works, but I don't like 'DESIGN 2': Array
(
     [0] => 2
)

To find a compromise I created this class:

<?php
class FirstProcessedArgumentReturn {
     static function __callStatic(string $name, array $arguments) {
         $name($arguments);

         return $arguments[0];
     }
}

FirstProcessedArgumentReturn::array_shift([1, 2]);
//TODO: Test the method FirstProcessedArgumentReturn::array_push(...);
//TODO: Test the method FirstProcessedArgumentReturn::array_pop(...);
//TODO: Test the method ...

PHP Notice:  Undefined offset: 0 in /tmp/test.php on line 6

But as you can see, something does not work: the reason I leave you to 
imagine.

Some idea?

Back to comp.lang.php | Previous | NextNext in thread | Find similar | Unroll thread


Thread

value returned instead change the value of the variable alex <1j9448a02@lnx159sneakemail.com.invalid> - 2020-10-16 13:23 +0200
  Re: value returned instead change the value of the variable Jerry Stuckle <jstucklex@attglobal.net> - 2020-10-16 11:11 -0400
    Re: value returned instead change the value of the variable alex <1j9448a02@lnx159sneakemail.com.invalid> - 2020-10-16 18:36 +0200
  Re: value returned instead change the value of the variable "J.O. Aho" <user@example.net> - 2020-10-16 20:51 +0200
    Re: value returned instead change the value of the variable alex <1j9448a02@lnx159sneakemail.com.invalid> - 2020-10-17 09:26 +0200
      Re: value returned instead change the value of the variable "J.O. Aho" <user@example.net> - 2020-10-17 10:16 +0200

csiph-web