Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>PHP has different syntax compared with C++. I will try to point what you are mixing. I will not check if your code works because I believe, logic is not a problem you have.</p> <p>First of all, PHP has different ways to work with scope. Inside the function AddMatrix, you are setting value for the variables with function scope. I am assuming you want to set values to class variables. So, you must refer the current object.</p> <pre><code>public function AddMatrix(Matrix2&amp; $Matrix) { $this-&gt;m_m1 + $Matrix2.$m_m1; $this-&gt;m_m2 + $Matrix2.$m_m2; $this-&gt;m_m3 + $Matrix2.$m_m3; $this-&gt;m_m4 + $Matrix2.$m_m4; return $this; } </code></pre> <p>Note I am using the operator -> to access a class Attribute instead of ".". Thats another problem in your code. The operator "." is used to concatenate string. To access class attributes or functions we use ->. So, check it out how will be your function after that:</p> <pre><code>public function AddMatrix(Matrix2&amp; $Matrix) { $this-&gt;m_m1 + $Matrix2-&gt;m_m1; $this-&gt;m_m2 + $Matrix2-&gt;m_m2; $this-&gt;m_m3 + $Matrix2-&gt;m_m3; $this-&gt;m_m4 + $Matrix2-&gt;m_m4; return $this; } </code></pre> <p>Yes, I get rid of $ character after use ->. This is correct. We use $ only for a variable. Never when accessing object attributes.</p> <p>Another mistake...PHP do not use datatype for variables. Objects are references already. So, the &amp; operator is unnecessary. So, lets finish your function:</p> <pre><code>public function AddMatrix($Matrix2) { $this-&gt;m_m1 + $Matrix2-&gt;m_m1; $this-&gt;m_m2 + $Matrix2-&gt;m_m2; $this-&gt;m_m3 + $Matrix2-&gt;m_m3; $this-&gt;m_m4 + $Matrix2-&gt;m_m4; return $this; } </code></pre>
    singulars
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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