Php Fatal error: Cannot pass parameter 1 by reference in /srv/www/default/work/index.php on line 30 -


i have project need make dice roller class. class public private member variables , public member functions able modify member variables. constructor takes parameter maximum number of sides on dice rolled in case class later used non 6 sided dice rolls. it's throwwing error in title , i'm not sure how fix error. if pass private variables value member functions doesn't uphold variables value.

<?php /*  * base code of webgames.  * file has classes cards , dice  * version 1.0  * file gameslib.php  * build date 6/25/2015  *  * run library use include statement include file,  * or download whole library package , run all.  *  */ class gamedie {    private $dierollvalue = 0;    const minimum_die_sides = 1;    private $maxdiesides = 2;     public function __construct( &$initialmaxdiesides)    {         if (is_int ($initialmaxdiesides))        {            $maxdiesides = $initialmaxdiesides;            unset($initialmaxdiesides);            $this->setdieroll();        }        else        {              print '<script language="javascript">';            print 'alert("function: gameslib did not correctly set max die side value in constructor.")';            print '</script>';         }    }     public function setdiemaxsides( &$passeddiemaxsidesvalue)    {        if (is_int ($passeddiemaxsidesvalue))        {            $maxdiesides = $passeddiemaxsidesvalue;            unset($passeddiemaxsidesvalue);        }        else        {              print '<script language="javascript">';            print 'alert("function: gameslib did not correctly set max die side value in setdiemaxsidesvalue.")';        print '</script>';         }    }      public function getdieroll()     {         $this->$dierollvalue;     }      public function setdieroll()     {         $this->$dierollvalue = (mt_rand(gamedie::minimum_die_sides, $maxdiesides));     } } $onlydie = new gamedie(6);  print ($onlydie->getdieroll());  ?> 

the error in constructor:

public function __construct( &$initialmaxdiesides)

the error occurring because trying pass number 6 constructor expecting variable. when use & before parameter 1, saying pass reference. number 6 value , has no reference. can correct either making constructor accept variable without reference (public function __construct( $initialmaxdiesides)) or making function call:

$number = 6; $onlydie = new gamedie($number); 

when pass gamedie($number), $number variable , can passed reference.

that fix first issue, have several other issues in code.... it's assignment, i'll let figure out on own. :)


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -