0

The code below works and it is so clean:

<?php
    preg_match('/(bar)/', 'love hotel bar', $matches);
    print_r($matches);

As you can see before calling the function $matches is undefined, which normally should return an error... The function parameter is filled by value and it is accessible out scopes.

❌ Bad

<?php
$title = get_og_tag('title');
$description = get_og_tag('description');
echo $title; //My title

✅ Could be Good

<?php
get_og_tag($title, $description, $og_url, $og_image, $twitter_card);
echo $title; // [error] $title, $description, ..etc, undefined...

For the code's clarity cake How to create functions like this?

halid96
  • 33
  • 1
  • 7

0 Answers0