1

I am using a template of a "certificate of completion" for online courses for my website.

On the template it has placeholder function names where presumably values would be pulled from database or elsewhere.

For example:

Certificate of Completion
This is to certify that
$student.getFullName()
has completed the course
$course.getName()
with score of $grade.getPoints()%

To my understanding you cannot use a period in the middle of a PHP variable of function name. Can someone explain what this convention is [ i.e. $student.getFullName() ] and whether it is valid PHP or just some invalid pseudocode?

gndev1
  • 13
  • 2
  • 2
    Replace `.` with `->` you are trying to get a child element of a class like a function, not merge 2 strings together – desbest Jan 24 '22 at 19:47
  • Does this answer your question? [What does a . (dot) do in PHP?](https://stackoverflow.com/questions/6484968/what-does-a-dot-do-in-php) – myselfmiqdad Jan 24 '22 at 19:48
  • 1
    The dots look like javascript notation instead of PHP – aynber Jan 24 '22 at 19:50
  • You were right aynber, I assumed it was a PHP var based on it starting with $ but turns out it's a js variable. – gndev1 Jan 24 '22 at 22:39

1 Answers1

0

the answer

to call a method in php, use -> not .

(.) using in PHP

for combining two strings, like:

$str1 = "hello ";
$str2 = "world";

$str12 = $str1.$str2;

hello world

(.) using in js

It's called dot-notation, you can access properties on an object by specifying the name of the object, followed by a dot (period) followed by the property name. This is the syntax: objectName.propertyName;

Sarout
  • 821
  • 4
  • 25
  • 2
    Thanks. It turns out the placeholder variables were JS and I mistook them for PHP because I wasn't used to seeing a JS variable begin with "$". – gndev1 Jan 24 '22 at 22:40