Matt Wilmas | 1 Jul 2007 04:30

Interpolated strings and memory (Bug 40122) (Was: [PHP-DOC] cvs: phpdoc /en/language types.xml)

Hi Gwynne, all,

I think this "parsing variables within strings..." note should be removed,
as it's incorrect/misleading as far as I can tell.

First, I was never able to repeat the behavior with the code in the bug
report months ago, nor am I now (no matter what I try).  Second, and more
importantly, using concatenation (.) creates the *exact same* temporary
variables as interpolated strings (well, meaning the temp var that's used
for assignment or such), contrary to what Ilia said in the bug report, as
far as I know.  This is obvious in the code (and I had been working in that
area recently ;-)).

So unless someone can explain WHY the memory usage could be different, the
note should definitely be reverted, since there's nothing to be concerned
about.

Thanks,
Matt

----- Original Message ----- 
From: "Gwynne Amaya Raskind"
Sent: Thursday, June 14, 2007 8:20 PM
Subject: [PHP-DOC] cvs: phpdoc /en/language types.xml

> gwynne Fri Jun 15 01:20:55 2007 UTC
>
>   Modified files:
>     /phpdoc/en/language types.xml
>   Log:
(Continue reading)

Pavel Shevaev | 1 Jul 2007 09:24
Picon
Gravatar

Re: [PHP-DEV] toString() and Object #ID

On 6/30/07, Stanislav Malyshev <stas <at> zend.com> wrote:
> > always helpful). Is there any other way than casting an object to a
> > string to get an objects #ID?
>
> spl_object_hash?

Guys, excuse my being a little offtopic here, but why not introduce
standard "get_object_id" function in PHP6 which could be analogous to
"spl_object_hash"? IMHO it's a basic functionality which deserves to
be in the core...

-- 
Best regards, Pavel

--

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

Gwynne Raskind | 1 Jul 2007 09:27

Re: [PHP-DEV] toString() and Object #ID

On Jul 1, 2007, at 3:24 AM, Pavel Shevaev wrote:
>> > always helpful). Is there any other way than casting an object to a
>> > string to get an objects #ID?
>>
>> spl_object_hash?
> Guys, excuse my being a little offtopic here, but why not introduce
> standard "get_object_id" function in PHP6 which could be analogous to
> "spl_object_hash"? IMHO it's a basic functionality which deserves to
> be in the core...

+1 on PHP_FEALIAS()ing this.

-- Gwynne, Daughter of the Code
"This whole world is an asylum for the incurable."

--

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

Sebastian Bergmann | 1 Jul 2007 10:10
Picon
Gravatar

Re: [PHP-DEV] toString() and Object #ID

Pavel Shevaev schrieb:
> Guys, excuse my being a little offtopic here, but why not introduce
> standard "get_object_id" function in PHP6 which could be analogous to
> "spl_object_hash"? IMHO it's a basic functionality which deserves to
> be in the core...

 SPL is "in the core" AFAIAC.

-- 
Sebastian Bergmann                          http://sebastian-bergmann.de/
GnuPG Key: 0xB85B5D69 / 27A7 2B14 09E4 98CD 6277 0E5B 6867 C514 B85B 5D69

--

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

Marcus Boerger | 1 Jul 2007 13:12
Picon

Re: [PHP-DEV] toString() and Object #ID

Hello Gwynne,

  no more unnecessary aliases please.

marcus

Sunday, July 1, 2007, 9:27:25 AM, you wrote:

> On Jul 1, 2007, at 3:24 AM, Pavel Shevaev wrote:
>>> > always helpful). Is there any other way than casting an object to a
>>> > string to get an objects #ID?
>>>
>>> spl_object_hash?
>> Guys, excuse my being a little offtopic here, but why not introduce
>> standard "get_object_id" function in PHP6 which could be analogous to
>> "spl_object_hash"? IMHO it's a basic functionality which deserves to
>> be in the core...

> +1 on PHP_FEALIAS()ing this.

> -- Gwynne, Daughter of the Code
> "This whole world is an asylum for the incurable."

Best regards,
 Marcus

--

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

(Continue reading)

Pavel Shevaev | 1 Jul 2007 13:42
Picon
Gravatar

Re: [PHP-DEV] toString() and Object #ID

>
>  SPL is "in the core" AFAIAC.

I really want to hope it will be in PHP6. Still IMHO get_object_id
sounds much better than spl_object_hash and it will be much easier(and
more logical) to locate this function in "Class/Object Functions"
section of documentation than in SPL...

-- 
Best regards, Pavel

--

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

Marcus Boerger | 1 Jul 2007 15:45
Picon

Re: [PHP-DEV] toString() and Object #ID

Hello Pavel,

  technically object id is neither what you get nor what you want. It is not
unique and thus not helpfull and we have no intention to ever provide a
function to access it. See mail archieve for reference on why we won't.
Also the function resides in extension SPL so correctly it is prefixed with
'spl_'. Furthermore it is no engine specific function but an object oriented
programming specific one. So SPL indeed is a very good place for it. Lastly
the function per design hashes the unique input it gives as we do not want
to make it more complex than necessary or give you stuff that leads to
missuse. Again see mail archive for why. That said the name appears to be
the best option already.

marcus

Sunday, July 1, 2007, 1:42:02 PM, you wrote:

>>
>>  SPL is "in the core" AFAIAC.

> I really want to hope it will be in PHP6. Still IMHO get_object_id
> sounds much better than spl_object_hash and it will be much easier(and
> more logical) to locate this function in "Class/Object Functions"
> section of documentation than in SPL...

> -- 
> Best regards, Pavel

Best regards,
 Marcus
(Continue reading)

Pavel Shevaev | 1 Jul 2007 21:18
Picon
Gravatar

Re: [PHP-DEV] toString() and Object #ID

> Again see mail archive for why. That said the name appears to be
> the best option already.

Oh, yes, you're right spl_object_hash does its job and does it very
well, there's really no point rename it(or make an alias) into
object_get_id. I should have stated more clear what I think
object_get_id could actually be.

How about object_get_id being a function returning the very first line
of var_dump's output being applied to the object? Let me be a bit more
specific, here's an example of var_dump usage:

$ php -r "class Foo{};$foo = new Foo();var_dump($foo);"
object(Foo)#1 (0) {
}

What I actually need, not the object hash but simply its unique id.
And in this case "object(Foo)#1" would be just fine. How can I get it?
The only way AFAIK is to surround var_dump with
ob_start/ob_get_contents/ob_end_clean functions and extract this
value.

The problem with approach is if one has a complex object connected
with a graph of other complex objects(with recursive links) var_dump
may take a _very_ long time to complete.
And this is what object_get_id could do - simply return object id
prefixed with the class name.

--

-- 
Best regards, Pavel
(Continue reading)

Lars Schultz | 1 Jul 2007 21:38
Picon

Re: [PHP-DEV] toString() and Object #ID


> What I actually need, not the object hash but simply its unique id.
> And in this case "object(Foo)#1" would be just fine. How can I get it?
That was my original Question too;) It's been stated that the automatic 
cast into a string even if it does not implement the __toString() 
function was "absolute nonsense"...but it really helped alot when you 
needed to check for errors quickly and easily. Why make something harder 
than it has to be.

Why not allow the old behaviour as long as the __toString is not 
implemented? Or rather something like a default implementation which is 
used autmatically for every class which doesn't implement it itself?

public function __toString(){
    return 'Object '. get_class($this) .'('. get_object_id($this) .')';
}

That'd be nice and no code breakage would result. Isn't that an approach 
that fits into the PHP philosophy? The new behaviour reminds me of 
Java's "the more userland-code, the better".

--

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

Lars Schultz | 1 Jul 2007 22:23
Picon

Re: [PHP-DEV] toString() and Object #ID


>  The problem is that there is no such unique id in the current engine.
>   
Okay!;) That's a very good reason, I guess;) Explains a lot. Why not use 
spl_object_hash instead of the old default behaviour?

--

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


Gmane