valore restituito al posto modificare il valore della variabile

7 views
Skip to first unread message

alex

unread,
Oct 16, 2020, 7:04:03 AM10/16/20
to
// DESIGN 1
echo "Non funziona, ma mi piace il 'DESIGN 1' ";
$arr = [1, 2];
print_r(
array_shift($arr)
);

// DESIGN 2
echo "Funziona, ma non mi piace il 'DESIGN 2': ";
$arr = [1, 2];
array_shift($arr);
print_r(
$arr
);

Output:

Non funziona, ma mi piace il 'DESIGN 1': 1

Funziona, ma non mi piace il 'DESIGN 2': Array
(
[0] => 2
)

Per trovare un compromesso mi son creato questa classe:

<?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

Ma come vedete qualcosa non funziona: il motivo lo lascio immaginare.

Qualche idea?

alex

unread,
Oct 16, 2020, 7:19:48 AM10/16/20
to
Il 16/10/20 13:03, alex ha scritto:
Precisazione:
Non funziona: cioè viene restituto 1 al posto dell'array.
Reply all
Reply to author
Forward
0 new messages