Hi, I have a small question, suppose you have a function which returns an array, the normal way of data gathering :
<?php
function blahfunction( $string )
{
// Do something here
return $result;
}
$handle = blahfunction('blah');
echo $handle['data'];
?>
I wanna combine two last lines in one, could it possible ? for example something like blah(‘blah’){‘data’} , does the function get any index ?
thanks.
You mean something like this?
echo blahfunction('blah')['data'];
Did you try?
yes but returns error : $PostName = $Blog->GetPostNameByID( $ID )[‘post-name’];
What error?
And are you sure that GetPostNameByID( $ID ) returns an array? Sounds to me like a method that returns a name of a post, not an array.
yes it returns array ,
public function GetPostNameByID( $id )
{
if( $this->ItemExists( $id , 'posts' , 'id' ) === TRUE )
return $this->GetRecord("select * from `posts` where `id` = '".$id."'" , 'ASSOC');
}
$Blog->GetPostNameByID('4'); // return array( 'post-name' => 'something')
Ok, so what is the error you’re getting?
Parse error: parse error in F:\wamp\www\—\blog\html\comments.php on line 9
Line9 = $PostName = $Blog->GetPostNameByID( $ID )[‘post-name’];
<?php
function blahfunction( $string )
{
$result = [
'data' => $string,
'data2' => $string,
'data3' => $string,
'data4' => $string
];
return $result;
}
//$handle = blahfunction('blah');
echo call_user_func(blahfunction, 'blah')['data'];
?>
Though what you’re looking for is method chaining, i.e. methods that return objects.
system
10
call_user_func($Blog->GetPostNameByID, 'blah')['data'];
Though, again, what you’re looking for is method chaining, i.e. methods that return objects.
but it still has error 
Parse error: parse error in F:\wamp\www\—\blog\html\comments.php on line 9
$PostName = call_user_func($Blog->GetPostNameByID, $ID)['post-name'];
system
12
It should work: http://www.sitepoint.com/forums/showthread.php?855985-obj()-gt-var-syntax-for-accessors&p=5129168&viewfull=1#post5129168
Need more info on what you’re having and what you’re doing.
<hr>
print_r( $Blog->GetPostNameByID( $ID ) );
gives you what?
Off Topic:
OOP programming = Object Oriented Programming programming