momanroman Posted March 27, 2014 Share Posted March 27, 2014 Apologies if this is simples. I'm adapting an ecommerce payment module, which comes as a class. I have written some extra code (as a function) to strip the numbers from a postcode & addess for card verification purposes. My issue is I cannot test this very easily live so I need to know the syntax is mostly correct. For example. (structure only, most code stripped) class payment module { var $code, $title, $description, $enabled;// class constructor function moduleconst() { // constructor code in here }// class methods function method1() { // code in here } function method2() { // code in here } } My problem is simple, how do I call function1 from within function2? Can I just call it straight ? ie: function method2() { method1(); } Iain Quote Link to comment https://forums.phpfreaks.com/topic/287336-class-functions/ Share on other sites More sharing options...
Solution Ch0cu3r Posted March 27, 2014 Solution Share Posted March 27, 2014 (edited) Can I just call it straight ? No, you need to reference the class ($this). So you'd use $this->method1() The same applies to accessing properties too. Have a read of http://php.net/manual/en/language.oop5.basic.php Edited March 27, 2014 by Ch0cu3r Quote Link to comment https://forums.phpfreaks.com/topic/287336-class-functions/#findComment-1474132 Share on other sites More sharing options...
momanroman Posted March 27, 2014 Author Share Posted March 27, 2014 Perfect, thanks.. Same as Java script then, I thought as much. Many thanks. Quote Link to comment https://forums.phpfreaks.com/topic/287336-class-functions/#findComment-1474133 Share on other sites More sharing options...
.josh Posted March 27, 2014 Share Posted March 27, 2014 My issue is I cannot test this very easily live so I need to know the syntax is mostly correct. Are you saying you do not have a development environment to test your code changes before pushing live? Do you really think it's a good idea to push untested changes live, especially when money stuff is involved?? Pushing untested code into production should NOT be an option, period. Especially when there is a user's personal info and/or money involved. But in any case, you call like this: $this->method1(); Quote Link to comment https://forums.phpfreaks.com/topic/287336-class-functions/#findComment-1474134 Share on other sites More sharing options...
momanroman Posted March 27, 2014 Author Share Posted March 27, 2014 Hi, Yes there is a dev/test envirovent but that would mean cloning the whole site and database to use, something I am trying to avoid. I have tested my function already and it is rock solid, it is a fairly straight forware regex function from the post code. Its already been integrated into the module with no error, I just need to call it, job done, I beleive, we shall see. Quote Link to comment https://forums.phpfreaks.com/topic/287336-class-functions/#findComment-1474138 Share on other sites More sharing options...
Psycho Posted March 27, 2014 Share Posted March 27, 2014 (edited) Hi, Yes there is a dev/test envirovent but that would mean cloning the whole site and database to use, something I am trying to avoid. I have tested my function already and it is rock solid, it is a fairly straight forware regex function from the post code. Its already been integrated into the module with no error, I just need to call it, job done, I beleive, we shall see. Can you please share the site that you are working on? I want to make sure to never visit it. You state there is a dev/test environment but that you would have to clone the whole site and database. If there is a dev/test environment then doesn't it already have the code and DB for the site?. Otherwise the dev/test environment isn't serving it's purpose. Well, actually you need several such environments - including a stage environment. My company has very strict rules about code progression to production as well as a full auditing system for code check-in and test sign off. Every once in a while someone says there is a 'simple' fix with little to no regression risk that has to get put out without going through the process. More often then not it causes more problems than it was supposed to resolve. FYI: You should NEVER clone production data to your test environments - big no, no. The code is fine, but the database should not. There needs to be processes in place so that the access to the production database is limited to only those individuals that must have it. If data is needed from production,troubleshooting for example, then the specific data should be retrieved w/o any user personal information. Or, if that information is needed, there must be an audit process. Edited March 27, 2014 by Psycho Quote Link to comment https://forums.phpfreaks.com/topic/287336-class-functions/#findComment-1474148 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.