Re: [PHP] self operator within a double quoted string

2013-04-17 Thread Matijn Woudt
On Wed, Apr 17, 2013 at 10:19 PM, Marco Behnke  wrote:

> Or use printf which is much more readable.
>

Are you serious about this? How would printf make things more readable?
Given a string with some %s %d etc in it, and then at the end you're giving
the stuff that replaces them. I fail to see how that improves readability
when you can put the variables in the string at exactly the place they are
printed, so the final string can be read as a somewhat normal text.


Re: [PHP] self operator within a double quoted string

2013-04-17 Thread Marco Behnke
Am 17.04.13 20:59, schrieb Matijn Woudt:
> On Wed, Apr 17, 2013 at 7:47 PM, NaMarPi  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: ma...@behnke.biz

Softwaretechnik Behnke
Heinrich-Heine-Str. 7D
21218 Seevetal

http://www.behnke.biz




signature.asc
Description: OpenPGP digital signature


Re: [PHP] self operator within a double quoted string

2013-04-17 Thread Matijn Woudt
On Wed, Apr 17, 2013 at 7:47 PM, NaMarPi  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.

- Matijn