jake-coder
12/30/2019 - 3:49 PM

PHP Functions

// Arguments are placeholders to be defined in a different spot
// x and y are arguments
// They are defined when they are called
 
functionTest(x, y)
{
  x + y;
}
 
functionTest(10, 10);
 
// These functions can be used elsewhere
// In OOP, functions in Classes are methods
// With public methods you can call functions using the $this keyword
 
$this->functionTest(10, 10);
 
// Model Level Functions
 
// The argument is general
 
public function isValidYard($store_num)
    {
        if ($this->allowedStores->contains($this->store_num) || !$this->allowedStores)
        {
            return true;
        }
    }
    
// Controller or Job Level Functions
 
// The arguments point to the spot in memory
 
if (!$promo->isValidSKU($item['sku'])) {
            throw new PromoCodeException('Invalid Product');
        }
        
// You can also use $item->sku