php - Classes - require conflict in constructor -


i'm coding wordpress plugin , i'm not sure regarding function name conflict..

i have file named test_handling.php contains following content :

function testing() { echo 'test'; } 

i included file in class constructor (file named testcls.class.php) :

class testcls {    function __construct() {       require_once('test_handling.php');        testing();    }     function otherfunction() {       testing();    }     // ... } 

in case, know if testing() function available in testcls class, or can create conflicts if other wp plugin has function same name ?

even same name, functions have different scope if defined class method. make call regular function following:

testing(); 

and result be:

'test' 

the class method need instance of class or statically called. call method class need following formats:

$class->test(); 

or

otherplugin::test(); 

to sum up, function test different if defined class method. then, not have conflicts.

other way encapsulate function , make sure using right 1 namespaces. if use namespace in test_handling.php

<?php namespace myname;  function testing(){echo 'test';} ?> 

you access function test this:

<?php  require_once "test_handling.php";  use myname;  echo myname\testing(); 

now sure function calling.


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -