How to update a function of other class from another class
How to update a function of other class from another class
I can call a function from other class but can't update/overwrite it from other class. is there any way to update a function of other class in different file from other class's function in different file.
thanks
file A.php
class FPDF
function header
//some code
file B.php
Class Users extents basecontroller
function viewPDF
require_once(A.php)
$pdf = new FPDF
$pdf->Header()
require_once(A.php);
Class PDF extends FPDF
// Page header
function Header()
// Logo
// Line break
$this->Ln(100);
Could you please provide a brief code excerpt? Are you sure about the class you're trying to extend is not a
final
one?– fabrik
Sep 13 '18 at 7:03
final
What do you mean by the update, do you want to change the code of that function or just want to execute that function or what? Please specify with some code snippet.
– Ashok Gujjar
Sep 13 '18 at 7:04
what you mean by update a function of other class.Please ask question properly and show Piece of code where you stuck
– Harry baldaniya
Sep 13 '18 at 7:06
I am using codeigniter framwork, i used require to include that file which contains the function i need to update. and it shows error if i use extent that class, it says constant fpdf already defined
– Danial
Sep 13 '18 at 7:08
1 Answer
1
I think that the structer of your files should be something as
file A.php
class FPDF
function header
//some code
file library/Pdf.php
require_once(A.php);
Class Pdf extends FPDF
// Page header
function Header()
// Logo
// Line break
$this->Ln(100);
file Users.php
Class Users extents basecontroller
function viewPDF
$this->load->library('pdf');
$this->pdf->Header()
the header function is calling automatically from many different functions in file A.php i dont want header funciion to run 1 time only from library. i want when ever the header function runs, the updated header function from runtime should appear each time the header function executes.
– Danial
Sep 13 '18 at 8:50
if you are unable to solve this, lets consider file A.php and file users.php only. Suppose I have written some code and query in header in file A.php, how can i send where criteria from file users.php to file A.php?
– Danial
Sep 13 '18 at 9:02
If you don't change a code of file A, you cant force that code to use your extended header function. But if you create object of class "pdf" any call to it will use new header function, even in the code of file A.
– splash58
Sep 13 '18 at 9:12
I have managed to do this other way round, i declared session variable in file users.php and used that in file A.php. but still curious about this that why function header is not overriding at runtime. there should be a way to run same function with different value assigned at runtime.
– Danial
Sep 13 '18 at 9:14
Thanks for contributing an answer to Stack Overflow!
But avoid …
To learn more, see our tips on writing great answers.
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Show a small example of what you want to achieve
– splash58
Sep 13 '18 at 7:02