Re: Pseudo-objects (methods on arrays, strings, etc.)

From: Date: Tue, 17 Jul 2012 19:53:03 +0000
Subject: Re: Pseudo-objects (methods on arrays, strings, etc.)
References: 1 2 3 4 5 6 7 8 9 10  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message

On 17.07.2012, at 23:20, Stas Malyshev wrote:

> Hi!
> 
>> That would be: tokenizer + static analysis (with type inference) + replacing some of the
>> tokens.
>> Not a trivial task, but definitely doable.
> 
> So what would this tool do with this code?
> 
> $a = getFirstArrayName();
> $b = getSecondArrayName();
> $$a = $$b;
> $b[1] = 0;


Something like this:

   $a = getFirstArrayName();
   $b = getSecondArrayName();
   if ($$b instanceof ArrayObject) {
       $$a = clone $$b;
   } else {
       $$a = $$b;
   }

   $b[1] = 0;

> Or this:
> 
> include 'a.inc';
> $a = $b;
> include 'b.inc';
> 
> where a.inc has array $a and b.inc has something like $b[1] = 0; but you
> have no way of knowing it since by the time you run the tool a.inc and
> b.inc are not available to it (think config files).

well, the same as above. not pretty, but that's a safe fallback when type inference is not
available.


Attachment: [application/pgp-signature] Message signed with OpenPGP using GPGMail signature.asc

Thread (66 messages)

« previous php.internals (#61377) next »