Calling php function from inside another function

user6646487

Maybe you guys can help me I am trying to do this:

public function index()
{
    $r = array();
    //some code   
    echo json_encode($this->utf8ize($r));
}

public function utf8ize($d) {
   //some code
    return $d;
}

But I get the "Call to undefined function utf8ize()" error

Why?

Edit 1: The complete code

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Solicitud extends MX_Controller {

public function __construct()
{
    /*
    parent::__construct();

    if(!$this->input->is_ajax_request())
    {
        show_404();
        exit();
    }
    else
    {
    */
        $this->load->model('Solicitud_model', 'Model');
    //}
}

public function index()
{
    $bandera = $this->input->post('bandera');
    $r = array();
    if ($bandera == 1){
        $result = $this->Model->getConsulta($this->session->session_facultad_apps);
        $r = array("data"    => $result,
            "success" => true,
            "bandera" => $bandera);
    }else if($bandera == 2)
    {
        $result = $this->Model->get($this->session->session_facultad_apps);
        $r = array("data"    => $result,
            "success" => true,
            "bandera" => $bandera);

    }else if ($bandera == 3){
        $result = $this->Model->getAsigna($this->session->session_facultad_apps);
        $r = array("data"    => $result,
            "success" => true,
            "bandera" => $bandera);
    }


    echo json_encode(utf8ize($r));
}

public function utf8ize($d) {
    if (is_array($d)) {
        foreach ($d as $k => $v) {
            $d[$k] = utf8ize($v);
        }
    } else if (is_string ($d)) {
        $d = iconv('UTF-8', 'ISO-8859-1', $d);
        return utf8_encode($d);
    }
    return $d;
}
Philipp

this is used to reference the current instance of an object. In your case, you missed the reference to this for the recursive call.

Simple solution - also add $this-> to the inner utf8ize call

echo json_encode($this->utf8ize($r));

...

public function utf8ize($d) {
    if (is_array($d)) {
        foreach ($d as $k => $v) {
            $d[$k] = $this->utf8ize($v);
        }
    } else if (is_string ($d)) {
        $d = iconv('UTF-8', 'ISO-8859-1', $d);
        return utf8_encode($d);
    }
    return $d;
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Calling a function from inside another function?

From Dev

calling a function inside a class from another class php

From Dev

Calling a function that's inside another function from a function

From Dev

Calling undeclared function template from inside another function template

From Dev

Calling function inside function in another function

From Dev

PHP calling function from another file not working

From Dev

PHP - Calling Use from another Function

From Dev

Calling a variable from another function inside another file

From Dev

Calling local function inside another local function

From Javascript

Calling a Function defined inside another function in Javascript

From Dev

Calling a function inside another function in React

From Dev

C++ Calling function inside another function

From Dev

Calling random function inside another function

From Dev

Calling a function inside another function in JavaScript

From Dev

Javascript: Calling a function inside another function

From Dev

Python : Calling functions from inside another function parameter

From Dev

Calling property of One Function From Inside Another Javascript

From Dev

Calling a Javascript function inside a DIV from another DIV

From Dev

Calling a Function inside a Controller from another Controller - AngularJS

From Dev

Calling one bash function from inside another as a specified user

From Dev

Python calling function in an function from another function

From Dev

PHP is there a way to add elements calling a function from inside of array

From Dev

Calling PHP function file_put_contents From Inside JQuery

From Dev

jquery - calling function from inside function

From Dev

Javascript calling function from inside same function

From Java

Calling a function from another package

From Dev

flask calling a function from another

From Dev

Calling a function from another in ReactJs

From Dev

Calling a function from another Project

Related Related

  1. 1

    Calling a function from inside another function?

  2. 2

    calling a function inside a class from another class php

  3. 3

    Calling a function that's inside another function from a function

  4. 4

    Calling undeclared function template from inside another function template

  5. 5

    Calling function inside function in another function

  6. 6

    PHP calling function from another file not working

  7. 7

    PHP - Calling Use from another Function

  8. 8

    Calling a variable from another function inside another file

  9. 9

    Calling local function inside another local function

  10. 10

    Calling a Function defined inside another function in Javascript

  11. 11

    Calling a function inside another function in React

  12. 12

    C++ Calling function inside another function

  13. 13

    Calling random function inside another function

  14. 14

    Calling a function inside another function in JavaScript

  15. 15

    Javascript: Calling a function inside another function

  16. 16

    Python : Calling functions from inside another function parameter

  17. 17

    Calling property of One Function From Inside Another Javascript

  18. 18

    Calling a Javascript function inside a DIV from another DIV

  19. 19

    Calling a Function inside a Controller from another Controller - AngularJS

  20. 20

    Calling one bash function from inside another as a specified user

  21. 21

    Python calling function in an function from another function

  22. 22

    PHP is there a way to add elements calling a function from inside of array

  23. 23

    Calling PHP function file_put_contents From Inside JQuery

  24. 24

    jquery - calling function from inside function

  25. 25

    Javascript calling function from inside same function

  26. 26

    Calling a function from another package

  27. 27

    flask calling a function from another

  28. 28

    Calling a function from another in ReactJs

  29. 29

    Calling a function from another Project

HotTag

Archive