On Wed, Feb 15, 2023, at 1:35 PM, Thomas Hruska wrote:
> On 2/15/2023 6:03 AM, Lydia de Jongh wrote:
>> Hi,
>> Very interesting topic! On which I have NO experience 🙈
>> 
>> 
>> In some other languages every variable IS an object..... by default.
>> 
>> As far as I understand, the code above is meant as internal.
>> But what if any variable is a small object.
>> Has this been ever considered? Or would it use too much performance?
>> 
>> $oString = 'my text';
>> 
>> $oString->toUpper();
>> 
>> echo $oString;  // 'MY TEXT'
>
> The above represents a significant amount of scope creep but it's 
> certainly interesting.  So let's explore it a bit and gauge the response.
>
> The above code will currently throw an error.  Significant global 
> adoption of such a change will take a fairly long time - probably a 
> decade, maybe longer.
>
> AFAIK, there is nothing technically preventing the core Zend engine from 
> accepting a -> token after a string variable and calling a function that 
> performs an inline modification of the string.
>
> As a brief test, I just ran the example code through PHP and got:  "PHP 
> Fatal error:  Uncaught Error: Call to a member function toUpper() on 
> string in test.php:4"  The error message shows that Zend engine clearly 
> already recognizes toUpper() as an attempted function/method call on a 
> string...it just doesn't know what to do with it.  So the logic for 
> supporting -> method calls on strings appears, at least from my very 
> brief test, to already be mostly in place.  Nice!

*snip*

What you're describing here is "scalar methods", which has been discussed on 
and off for many years.  The idea has its proponents, but also its detractors.  
(I'm in the detractor camp, personally, as I think there are better, more 
flexible options.)

I would strongly recommend not allowing "faster string manipulation" to scope 
creep into scalar methods, as that will almost guarantee that it never comes to 
fruition. :-)  IF scalar methods were to happen, they should happen on their 
own.

--Larry Garfield

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php

Reply via email to