Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > it.comp.www.php > #22870 > unrolled thread
| Started by | alex <1j9448a02@lnx159sneakemail.com.invalid> |
|---|---|
| First post | 2020-10-16 13:03 +0200 |
| Last post | 2023-07-20 20:48 -0700 |
| Articles | 3 — 2 participants |
Back to article view | Back to it.comp.www.php
valore restituito al posto modificare il valore della variabile alex <1j9448a02@lnx159sneakemail.com.invalid> - 2020-10-16 13:03 +0200
Re: valore restituito al posto modificare il valore della variabile alex <1j9448a02@lnx159sneakemail.com.invalid> - 2020-10-16 13:19 +0200
Re: valore restituito al posto modificare il valore della variabile massiws <m.simonini@gmail.com> - 2023-07-20 20:48 -0700
| From | alex <1j9448a02@lnx159sneakemail.com.invalid> |
|---|---|
| Date | 2020-10-16 13:03 +0200 |
| Subject | valore restituito al posto modificare il valore della variabile |
| Message-ID | <rmbums$4ar$1@gioia.aioe.org> |
// 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?
[toc] | [next] | [standalone]
| From | alex <1j9448a02@lnx159sneakemail.com.invalid> |
|---|---|
| Date | 2020-10-16 13:19 +0200 |
| Message-ID | <rmbvkh$jbe$1@gioia.aioe.org> |
| In reply to | #22870 |
Il 16/10/20 13:03, alex ha scritto:
> // 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?
Precisazione:
Non funziona: cioè viene restituto 1 al posto dell'array.
[toc] | [prev] | [next] | [standalone]
| From | massiws <m.simonini@gmail.com> |
|---|---|
| Date | 2023-07-20 20:48 -0700 |
| Message-ID | <029d87dd-4f2c-471d-8695-4d9dcff87348n@googlegroups.com> |
| In reply to | #22871 |
Il giorno venerdì 16 ottobre 2020 alle 13:19:48 UTC+2 alex ha scritto:
> Il 16/10/20 13:03, alex ha scritto:
> > // 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?
> Precisazione:
> Non funziona: cioè viene restituto 1 al posto dell'array.
https://www.php.net/manual/en/function.print-r.php
"If you would like to capture the output of print_r(), use the return parameter. When this parameter is set to true, print_r() will return the information rather than print it."
[toc] | [prev] | [standalone]
Back to top | Article view | it.comp.www.php
csiph-web