0

I need to call a function from a separate class file, let says:

class Functions { public function seoUrl($string) { $string = strtolower($string); $string = preg_replace("~[^\p{L}\p{N}\n]+~u", "-", $string); $string = preg_replace("/[\s-]+/", " ", $string); $string = preg_replace("/[\s_]/", "-", $string); return $string; } } 

I want Functions::seoUrl() to be call in another class file:

class Product { public function goto_url($url) { return Functions::seoUrl($url); } } 

I get error:

Fatal error: Class 'Functions' not found in C:\xampp\htdocs...

3
  • Not really too great at php but a few questions to help possible answerers. Is the class in another file? And the function you're trying to call doesn't seem to be a static function, meaning it shouldn't work unless you instantiate it. Commented Apr 21, 2017 at 2:03
  • Did you use require to load your class Functions? Commented Apr 21, 2017 at 2:07
  • @A.Lau Thank you, I had public static function seoUrl($string) and now I can use all method across separate classes. Commented Apr 21, 2017 at 2:16

2 Answers 2

1

Functions::seoUrl() is the way to call static method. You need to declare your method seoUrl(string) as static, or create an object for your Functions class

$functions = new Functions(); $functions->seoUrl(string); 
Sign up to request clarification or add additional context in comments.

Comments

1

Here you getting fatal just because your PHP is not able to locate class Functions For this you have two options either you require that file or add some autoloading for this.

<?php require_once 'Functions.php'// where your Class functions resides. class Product { public function goto_url($url) { return Functions::seoUrl($url); } } 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.