Jump to content

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. Edited by kicken

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>
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.