Note that there are some explanatory texts on larger screens.

plurals
  1. POundefined variable error(PHP)
    primarykey
    data
    text
    <p>I got those error messages as follows:</p> <p>Notice: Undefined variable: availableTest in /Users/alexhu/NetBeansProjects/menagerie/svn/trunk/apps/frontend/modules/legacy/legacy_lib/lib/classes/AppointmentTime.php on line 382</p> <p>Fatal error: Call to a member function getName() on a non-object in /Users/alexhu/NetBeansProjects/menagerie/svn/trunk/apps/frontend/modules/legacy/legacy_lib/lib/classes/AppointmentTime.php on line 382</p> <p>And my codes is as follows:</p> <pre><code>protected function replaceEmailTokens($emailContents) { $additionalTestsSelected = array(); $additionalTests = $this-&gt;getAdditionalTestsSelected(); $additionalTestCostsSelected = $this-&gt;getAdditionalTestCostsSelected(); foreach($additionalTests as $availableTest) { $additionalTestCost = current($additionalTestCostsSelected); $additionalTestsSelected[] = array( 'id' =&gt; $availableTest-&gt;getID(), 'name' =&gt; $availableTest-&gt;getName(), 'cost' =&gt; $additionalTestCost-&gt;getFormattedCost() ); next($additionalTestCostsSelected); } $appointment = $this-&gt;getAppointment(); $tokens = array( '%DATE%' =&gt; $this-&gt;getAppointment()-&gt;getDate(), '%LOCATION%' =&gt; $this-&gt;getAppointment()-&gt;getLocation(), '%TIME%' =&gt; $this-&gt;getTime(), '%ROOM%' =&gt; $this-&gt;getRoom(), '%NAME%' =&gt; ($this-&gt;getUser() ? $this-&gt;getUser()-&gt;getFullName() : null), '%TZ%' =&gt; $this-&gt;getAppointment()-&gt;getShowTimeZone() ? $this-&gt;getAppointment()-&gt;getTimeZone() : '', '%AdditionalTestsSelected%' =&gt; $availableTest-&gt;getName(), ); return str_replace(array_keys($tokens), array_values($tokens), $emailContents); } </code></pre> <p>I want to get the value of $availableTest->getName() and put it into array $tokens. What is the right way to do that?</p> <pre><code>$additionalTestsSelected = array(); foreach($additionalTests as $availableTest) { //$additionalTestConfirmation[] = $availableTest-&gt;getName(); } $appointment = $this-&gt;getAppointment(); $tokens = array( '%DATE%' =&gt; $this-&gt;getAppointment()-&gt;getDate(), '%LOCATION%' =&gt; $this-&gt;getAppointment()-&gt;getLocation(), '%TIME%' =&gt; $this-&gt;getTime(), '%ROOM%' =&gt; $this-&gt;getRoom(), '%NAME%' =&gt; ($this-&gt;getUser() ? $this-&gt;getUser()-&gt;getFullName() : null), '%TZ%' =&gt; $this-&gt;getAppointment()-&gt;getShowTimeZone() ? $this-&gt;getAppointment()-&gt;getTimeZone() : '', '%AdditionalTestsSelected%' =&gt; $availableTest-&gt;getName(), ); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload