Re: self operator within a double quoted string

[email protected] (NaMarPi)
Newsgroups php.general
Message-ID <[email protected]>
I found that double quoted strings are more elegant in some situations
than single ones, and I like identical solutions for identical problems,
so that's why I asked this question.

But finally found a reason why use single quoted strings instead of double:
because the number of generated opcodes is less in the former case.

Here is a detailed explanation (the url does not exist anymore,
so make a search on the url and load the cashed version of the page):

blog.golemon.com/2006/06/how-long-is-piece-of-string.html

If anyone can run the vld package and share the currently relevant
opcodes, it will be appreciated.



>> On Wed, Apr 17, 2013 at 7:47 PM, NaMarPi <[email protected]> wrote:
>>
>>> I would like to use self and static operators inside a double quoted
>>> string,
>>> but do not find the way to accomplish that. Could you give me a right
>>> direction?
>>>
>>>
>>> http://3v4l.org/NDkdA
>>>
>>>
>>> class Foo {
>>>
>>>     public static $class_prop = 'Class_Property';
>>>     public $object_prop = 'Object_Property';
>>>
>>>     static function printClassProp() {
>>>         print 'prefix_' . self::$class_prop . '_postfix' . PHP_EOL;
>>>         print "prefix_{\\self::$class_prop}_postfix" . PHP_EOL;       //
>>> <-- issue here
>>>     }
>>>
>>>     function printObjectProp() {
>>>         print "prefix_{$this->object_prop}_postfix" . PHP_EOL;
>>>     }
>>> }
>>>
>>>
>>> $foo = new Foo;
>>> $foo->printObjectProp();
>>>
>>>
>>> Foo::printClassProp();
>>>
>>>
>> Hi,
>>
>> This is a bug/feature in php and is just not possible. Either use the
>> syntax you've used on the single quotes, or store the variable in a
>> temporary var before using the print.
>Or use printf which is much more readable.
>>
>> - Matijn
>>
>
>
>-- 
>Marco Behnke
>Dipl. Informatiker (FH), SAE Audio Engineer Diploma
>Zend Certified Engineer PHP 5.3
>
>Tel.: 0174 / 9722336
>e-Mail: [email protected]
>
>Softwaretechnik Behnke
>Heinrich-Heine-Str. 7D
>21218 Seevetal
>
>http://www.behnke.biz
>
>
>
>Attachment: [application/pgp-signature] OpenPGP digital signature signature.asc
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.