Home > Backend Development > PHP Tutorial > php- PHP uses an array to call a method in a class, and an error occurs

php- PHP uses an array to call a method in a class, and an error occurs

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2023-03-02 22:16:01
Original
1182 people have browsed it

php

/**

  • Enable session/session_start();/*
  • Include initialization file/include_once '../../../sys/config/db-cred.inc.php';/*
  • Define constants for configuration information /foreach ( $C as $name => $val ) {define($name, $val);}/*

  • Generate an associative array with form action as key
    */
    $actions = array(
    'event_edit' => array(
    'object' => 'Calendar',
    'method' => 'processForm',
    'header' => 'Location:../../'
    ),

    'user_login' => array(
    'object' => 'Admin',
    'method' = > 'processLoginForm',
    'header' => 'Location:../../'
    )
    );
    /**

  • Ensure that the anti-cross-site mark in the session is consistent with the submitted mark and the requested action is legal
    */
    if ( $_POST['token']==$ _SESSION['token'] &&
    isset($actions[$_POST['action']]) ) {
    $use_array = $actions[$_POST['action']];
    $obj = new $use_array'object' ;

    <code>if ( true == $msg=$obj->$use_array['method']() ) {    header($use_array['header']);    exit;} else {    die( $msg );}</code>
    Copy after login

    } else {
    //If the token/action is illegal, redirect to the homepage
    header("Location:../../");
    exit;
    }

  • function __autoload($class) {

    <code>$filename = "../../../sys/class/class.".$class.".inc.php";if ( file_exists($filename) ) {    include_once $filename;}</code>
    Copy after login

    }

    The main problem is this: $obj->$use_array'method'
    As soon as you get to this step, Function name must be a string in E:qampphtdocsSource Filespublicassetsincprocess.inc.php:40 Stack trace : #0 {main} thrown in E:qampphtdocsSource Filespublicassetsincprocess.inc.php on line 40 error.

    If you use $obj to directly call the processForm() or processLoginForm() method in this class, you can.
    Ask God for help.

Reply content:

http://blog.sina.com.cn/s/blog_8d7518cb0100zk1t.html

Related labels:
php
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template