The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> PHP Development
|
Reverse engineering classes and objects
Discuss Reverse engineering classes and objects in the PHP Development forum on Dev Shed. Reverse engineering classes and objects PHP Development forum discussing coding practices, tips on PHP, and other PHP-related topics. PHP is an open source scripting language that has taken the web development industry by storm.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

December 18th, 2012, 08:41 AM
|
|
Contributing User
|
|
Join Date: Jan 2004
Posts: 55
Time spent in forums: 9 h 9 m 14 sec
Reputation Power: 10
|
|
|
Reverse engineering classes and objects
I am in the process of migrating a site from one framework to another. In order to do this I am trying to leave the templates alone and write functions they require above them. When I have an object being requested like this:
PHP Code:
$this->wt_globals->language_selection(true)
How do I write the class / declare the object to return something? I have tried a few methods but they all fail.
|

December 18th, 2012, 09:25 AM
|
 |
Likely to be eaten by a grue.
|
|
Join Date: Oct 2006
Location: Pennsylvania, USA
|
|
|
This is a little more than vague. What is $this? You're using $this inside a template?
If that's the case, whatever class you're supposed to be in that $this would reference needs a member variable called $wt_globals, which itself is an object with a member function called language_selection()
__________________
HEY! YOU! Read the New User Guide and Forum Rules
"They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin
"The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002
Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
|

December 18th, 2012, 09:32 AM
|
|
Contributing User
|
|
Join Date: Jan 2004
Posts: 55
Time spent in forums: 9 h 9 m 14 sec
Reputation Power: 10
|
|
Yes, I agree it is a bit vague. $this exists in the old template and I don't have it in my new environment yet - which is what I am trying to achieve. I have tried doing something like this:
PHP Code:
class WT_Globals{
function WT_Globals(){
$this->language_selection();
}
public function language_selection(){
return "en";
}
}
But that doesn't work. How should it be written? I guess I need to declare $this somewhere - but I am not sure where or how.
ps. I should add the above class is what I managed to scrape from the existing code;
Last edited by keiron77 : December 18th, 2012 at 09:37 AM.
|

December 18th, 2012, 10:54 AM
|
 |
Likely to be eaten by a grue.
|
|
Join Date: Oct 2006
Location: Pennsylvania, USA
|
|
$this is only valid inside a class. You need something more like:
PHP Code:
class WT_Globals{
public function language_selection(){
return "en";
}
}
class Whatever_loads_your_template{
private $wt_globals;
public function __construct() {
$this->wt_globals = new WT_Globals();
}
public function renderTemplate() {
include('template.whatever.php');
}
}
That way, $this in the template will point to class Whatever_loads_your_template, which has wt_globals.
|

December 18th, 2012, 12:22 PM
|
|
Contributing User
|
|
Join Date: Jan 2004
Posts: 55
Time spent in forums: 9 h 9 m 14 sec
Reputation Power: 10
|
|
|
Great, thanks for the answer - that worked a treat.
I haven't really created classes or objects before - just interrogated other that already exist.
|

December 18th, 2012, 12:36 PM
|
 |
Likely to be eaten by a grue.
|
|
Join Date: Oct 2006
Location: Pennsylvania, USA
|
|
|
This is almost certainly a losing proposition by the way. If the site is small, just rewrite it. Why are you switching frameworks?
|

December 19th, 2012, 02:15 AM
|
|
Contributing User
|
|
Join Date: Jan 2004
Posts: 55
Time spent in forums: 9 h 9 m 14 sec
Reputation Power: 10
|
|
|
Our client has a US website and 3 European ones which we look after. They have built their US site in Code Ignighter which, as they look after it internally, isn't a problem for them. The European sites are to be built by us, but maintained by PR companies who need it as friendly as possible. So, we are building their sites in MODx which gives us the open framework to develop anything we want (quickly) but a nice interface, advanced permissions etc. for the contributors. So we don't have a complete disconnect from Code Ignighter my plan is to use their templates, untouched, and pull them into MODx. Because their templates contain variables, functions and objects already I need to recreate these to make it work. This means that if they update a template or create a new one I can just import it for us to use.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|