I am a beginner at programming. I am writing code using c开发者_JAVA技巧lass inheritance. Here is the full code:
require_once('db.php');
class Activity extends DatabaseCall //this is in db.php
{
public $name, $link, $activity_id;
public function oneActivity( $name, $link, $activity_id )
{
$this->name = $name;
$this->link = $link;
$this->activity_id = $activity_id;
}
private function activitiesArrays()
{
$this->sqlActivities(); //a protected function inherited from Parent
}
//Returns array of name + link + activity_id for random activity.
//Works with function activitiesArrays(), which returns An Array of arrays of
//names,links,and id's.
// @param <array> $namesLinksIds_Arrays An Array of arrays of names, links,and
//id's.
public function makesRandomActivity($namesLinksIds_Arrays)
{
$list($name, $linkk, $id) = $namesLinksIds_Arrays;
$length = count($name);
$rand = rand(0, $length-1);
$n = $name[$rand];
$l = $linkk[$rand];
$i = $id[$rand];
oneActivity($n, $l, $i);
}
}
Everything in this code works if I comment out this code:
public function makesRandomActivity($namesLinksIds_Arrays)
{
$list($name, $linkk, $id) = $namesLinksIds_Arrays;
$length = count($name);
$rand = rand(0, $length-1);
$n = $name[$rand];
$l = $linkk[$rand];
$i = $id[$rand];
oneActivity($n, $l, $i);
}
Please help me figure out why this code does not work. Any help/suggestions/tips appreciated.
The following line is incorrect :
$list($name, $linkk, $id) = $namesLinksIds_Arrays;
You want to use the list()
language construct -- so, remove the $
:
list($name, $linkk, $id) = $namesLinksIds_Arrays;
Using what you did, PHP intepreted the $list(...)
as calling a function which name would have been contained inside the (unexisting) $link
variable -- about that, see Variable functions.
Which basically means you were trying to assign $namesLinksIds_Arrays
to a function invokation -- which is why you were getting the following error message :
Fatal error: Can't use function return value in write context
精彩评论