Graphite icon indicating copy to clipboard operation
Graphite copied to clipboard

forceString modifies the variable passed to it

Open cgutteridge opened this issue 12 years ago • 4 comments

This bit me in the bottom in some code I was wriing. I think forceString( &$resource )should NOT be listed as part of the API and we should add a non-mutating version which does $string_uri = $graph->FN( $resource_or_string_uri ); whithout modifying the incoming value. Not sure what to call the fn though.

cgutteridge avatar Mar 27 '12 10:03 cgutteridge

I was looking at this, and wondering why we didn't rely on __toString() and (string) in almost all cases. That'll get us around the pass-by-reference behaviour

CloCkWeRX avatar Mar 27 '12 22:03 CloCkWeRX

Ah, because you can't call $foo = "a string"; $foo = $foo->toString();

Because in some contexts you want to be sure you're using a resource object, and in some sure you're using a string, but in many it's nice to not worry about it. $graph->resource( $x ) will accept a resource object or a string and return a resource. I think we need the inverse, maybe just $graph->string( $x ) which will accept either and always return a string of the URI or literal if a resource is passed, and just the string if $x is a string.

On 27/03/2012 23:47, Daniel O'Connor wrote:

I was looking at this, and wondering why we didn't rely on __toString() and (string) in almost all cases. That'll get us around the pass-by-reference behaviour


Reply to this email directly or view it on GitHub: https://github.com/cgutteridge/Graphite/issues/11#issuecomment-4737123

Christopher Gutteridge -- http://id.ecs.soton.ac.uk/person/1248

Graphite PHP RDF Library v1.5 released! http://graphite.ecs.soton.ac.uk/ University of Southampton Open Data Service: http://data.southampton.ac.uk/ You should read the ECS Web Team blog: http://blogs.ecs.soton.ac.uk/webteam/

cgutteridge avatar Mar 28 '12 07:03 cgutteridge

Not toString(); that we've been defining; but __toString() the magical method of magic-ness? http://au2.php.net/manual/en/language.oop5.magic.php#object.tostring

$foo = "a string"; print (string)$foo; // a string

class Foobar { public function __toString() { return "baaaaaa"; } }

$foo = new FooBar(); print (string)$foo; //baa ?

CloCkWeRX avatar Mar 28 '12 12:03 CloCkWeRX

Ah. I have never learned to use casting in PHP.... I didn't actually realise that was an option! neat.

On 28/03/12 13:08, Daniel O'Connor wrote:

Not toString(); that we've been defining; but __toString() the magical method of magic-ness? http://au2.php.net/manual/en/language.oop5.magic.php#object.tostring

$foo = "a string"; print (string)$foo; // a string

class Foobar { public function __toString() { return "baaaaaa"; } }

$foo = new FooBar(); print (string)$foo; //baa ?


Reply to this email directly or view it on GitHub: https://github.com/cgutteridge/Graphite/issues/11#issuecomment-4758594

Christopher Gutteridge -- http://id.ecs.soton.ac.uk/person/1248

/ Lead Developer, EPrints Project, http://eprints.org/ / Web Projects Manager, ECS, University of Southampton, http://www.ecs.soton.ac.uk/ / Webmaster, Web Science Trust, http://www.webscience.org/

cgutteridge avatar Mar 28 '12 14:03 cgutteridge