Jump to content

Call to undefined method x?


Yohanne

Recommended Posts

Hi all,

 

how to call a function where a function is decleared into different or other page?

 

 

page1.php

<?php
 class class_a
   {
     public function x();
       {
         code methods here.
       }
   }
?>

page2.php

<?php
 require_once 'page1.php';
 class class_b
   {
     public function __cinstruct()
      {
        $new_class_a = new class_a();
      }
     public function y();
       {
       
		: how to call x function? here

       }
   }
?>
Link to comment
https://forums.phpfreaks.com/topic/277577-call-to-undefined-method-x/
Share on other sites

First, remove the ; after function x() and function y() in the definitions

require_once("page1.php");
   
 class class_b
   {
     private $new_class_a;
       
     public function __construct($a)
      {
        $this->new_class_a = $a;
      }
      
     public function y()
       {
       
        $this->new_class_a->x();

       }
   }
   
$b = new class_b(new class_a());
$b->y();

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.