Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6136141
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:34:00+00:00 2026-05-23T17:34:00+00:00

require_once(‘classes/class.validation.php’); $array = $_POST[‘array’]; $pass_profanity = false; $validation = new Validation; function check_for_profanity($input){ if(is_array($input)){

  • 0
require_once('classes/class.validation.php');

$array = $_POST['array'];
$pass_profanity = false;
$validation = new Validation;
function check_for_profanity($input){
    if(is_array($input)){
        foreach($input as $row){
            if(is_array($row)){
                check_for_profanity($input);
            } else {
                $pass_profanity = $validation->check_for_profanity($row);
            }
        }
    } else {
        $pass_profanity = $validation->check_for_profanity($input);
        return;
    }
    return;
}
check_for_profanity($array);

But I get the error:

Notice: Undefined variable: validation in
/Library/WebServer/Documents/file.php on line 22

Fatal error: Call to a member function check_for_profanity() on a
non-object in /Library/WebServer/Documents/file.php
on line 2

I can’t figure it out, any thoughts???

Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T17:34:00+00:00Added an answer on May 23, 2026 at 5:34 pm

    You can either gain access to the variable in your function with global:

    function check_for_profanity($input){
        global $validation;
        ...
    }
    

    Or, the better way would be to retrieve it via a parameter:

    function check_for_profanity($input, $validation){
        ...
    }
    
    check_for_profanity($array, $validation);
    

    Read the PHP manual – variable scope for more information

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

class_1.php class class_1 { public function __construct() { require_once $_SERVER['DOCUMENT_ROOT'].'/array.php'; } } class_2.php class
require_once('Class.php'); $myArray = array(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15); // etc which is correct? foreach($myArray as $key => $val)
PHP manual suggests to autoload classes like function __autoload($class_name){ require_once(some_dir/.$class_name..php); } and this approach
--- A.php ---- require_once 'B.php'; class A { public function __constructor($x){...} public function foo()
require_once'modules/logger.php'; $Logger = new Logger(); require_once 'templates/list.php'; $Templates = new templatesList(); require_once 'widgets/list.php'; $Widgets
I have some files: core.php : require_once 'logger.php'; require_once 'smth_else.php'; $Logger = new Logger();
Is the following example appropriate for PHP's require_once construct? function foo( $param ) {
My first class: <?php require_once( 'error/DisconnectedHandler.php' ); require_once( 'error/NoSuchRequestHandler.php' ); class NetworkManager { public
The code I currently have: <?php /** PHPExcel */ require_once '../Classes/PHPExcel.php'; /** PHPExcel_IOFactory */
I have a section of code like the following: ---- file.php ---- require_once(mylib.php); function($a,$b)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.