Jump to content

What are these called?


jburridge

Recommended Posts

I'm trying to figure out what these examples of code are called?

 

"DB()"

"connect()"

 

I don't believe they are variables because they are not defined anywhere in another part of a script. I'm also wondering if someone knows where I can find a list of all of these so I get a better understanding of all the functions of php.

Link to comment
https://forums.phpfreaks.com/topic/282578-what-are-these-called/
Share on other sites

Functions. There are both built-in functions which are all documented in the php manual, and user-defined functions which would be defined in your codebase somewhere. Neither of the two examples you gave are built-in so they would be defined in your code somewhere.

They are called functions. They are usually defined as such:

 

function DB() {
  // do something
}

// call the function
DB();
They are also class methods, though the syntax is slightly different. Example:

 

class myClass {

  public function DB() {
    // do something;
  }

}

// call it
$myClass = new myClass();
$myClass->DB();
*usually* a function will accept arguments and return something. For example:

 

function makeLink($url,$text) {
  if (isset($url)&&isset($text)) {
    return "<a href='$url'>$text</a>";
  }
  return '';
}

// provide url and text and get an html marked up link in return
$link = makeLink('http://www.google.com','google!');
echo $link;
// output:
<a href='http://www.google.com'>google!</a>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.