drath Posted January 2, 2009 Author Share Posted January 2, 2009 @flyhoney No output at all, i've also tried several variations of what you gave me to see if it was just a param problem. Nothing will output except the -v data it seems. @DarkWater I/we concluded that the file_get_contents will not work for parsing the PHP files since it does not interpret it. Quote Link to comment https://forums.phpfreaks.com/topic/139052-redeclaring-class-dilemma/page/2/#findComment-728293 Share on other sites More sharing options...
DarkWater Posted January 2, 2009 Share Posted January 2, 2009 Err, that's the point. It's not supposed to interpret it. Quote Link to comment https://forums.phpfreaks.com/topic/139052-redeclaring-class-dilemma/page/2/#findComment-728306 Share on other sites More sharing options...
drath Posted January 2, 2009 Author Share Posted January 2, 2009 What I mean to say is it will ignore any variable declarations (and other stuff) in the output, so you can't get the variables from the php files using any method except eval which still declares the classes. fread/curl will also have the same problem. The only way it would work is if I used copy() to copy the version.php and made an alternate one, then somehow edited out the class name in the new one. Then did this every time the script was ran. I'm not really sure it would be possible to edit a class name in a .php file through .php. Quote Link to comment https://forums.phpfreaks.com/topic/139052-redeclaring-class-dilemma/page/2/#findComment-728318 Share on other sites More sharing options...
flyhoney Posted January 2, 2009 Share Posted January 2, 2009 Darkwater is saying that it is possible to read the php file as text, and then find where all the variables are declared, and then extract those values using regular expressions and the like. I still like my solution Quote Link to comment https://forums.phpfreaks.com/topic/139052-redeclaring-class-dilemma/page/2/#findComment-728323 Share on other sites More sharing options...
Mchl Posted January 2, 2009 Share Posted January 2, 2009 Another idea. How about you add a script to each site, that would get the data you need from this class and save to for example XML. Then just go from site to site and collect those xmls? Quote Link to comment https://forums.phpfreaks.com/topic/139052-redeclaring-class-dilemma/page/2/#findComment-728325 Share on other sites More sharing options...
drath Posted January 2, 2009 Author Share Posted January 2, 2009 @flyhoney How is that possible though, everything I tried ignores most of the php? Your idea is probably the best out of everything because it's the most efficient and doesn't require creating new files and the like, but I just can't get the execute to work... I'll probably have to investigate into a it a little bit myself but I can't really find any information on Google about executing other .php files and getting args/params. @Mchl Running the script on each of the sites would probably be another step I would not like to take; granted they could be cron'ed or something I guess. If possible, this could use my copy() idea so the script would output all the data dynamically every time the script is run so we wouldn't have to run the script on EVERY site. Again though, I don't think there's a way to replace a specific portion of the .php or .xml or whatever. Quote Link to comment https://forums.phpfreaks.com/topic/139052-redeclaring-class-dilemma/page/2/#findComment-728355 Share on other sites More sharing options...
flyhoney Posted January 2, 2009 Share Posted January 2, 2009 http://us2.php.net/features.commandline Quote Link to comment https://forums.phpfreaks.com/topic/139052-redeclaring-class-dilemma/page/2/#findComment-728357 Share on other sites More sharing options...
Mchl Posted January 2, 2009 Share Posted January 2, 2009 Again though, I don't think there's a way to replace a specific portion of the .php or .xml or whatever. If you just need to change class name it would be quite straightforward. Quote Link to comment https://forums.phpfreaks.com/topic/139052-redeclaring-class-dilemma/page/2/#findComment-728367 Share on other sites More sharing options...
drath Posted January 2, 2009 Author Share Posted January 2, 2009 @Mchl, which command would I use? Okay, let's say if I can actually copy version.php to version2.php... how would I go about just replace a class name in version2.php. Quote Link to comment https://forums.phpfreaks.com/topic/139052-redeclaring-class-dilemma/page/2/#findComment-728384 Share on other sites More sharing options...
Mchl Posted January 2, 2009 Share Posted January 2, 2009 You could 1. Load the file with class into a string using file_get_contents 2. Rename class using str_replace or other string functions into something like class123 3. Save this file in your directory with temporary name 4. include this temporary file to run it Quote Link to comment https://forums.phpfreaks.com/topic/139052-redeclaring-class-dilemma/page/2/#findComment-728385 Share on other sites More sharing options...
drath Posted January 2, 2009 Author Share Posted January 2, 2009 Sorry, about that. Everybody is probably really annoyed at me now, haha. Mchl, what I was saying in the posts above is there is no way to get the full class or even the class name using file_get_contents, fread, or curl. Unless there is some option/argument that will get everything rather than selective output - everything that I tried just strips more php. Quote Link to comment https://forums.phpfreaks.com/topic/139052-redeclaring-class-dilemma/page/2/#findComment-728393 Share on other sites More sharing options...
Mchl Posted January 2, 2009 Share Posted January 2, 2009 file_get_contents loads whole text in a file into a string variable. You can then do with it anything you can do with a string. <?php class classname { public $variable1 = "foo"; } $f = file_get_contents("test.php"); echo $f; $f = str_replace("classname","classfoo",$f); echo $f; $h = fopen("test1.php","w"); fwrite($h,$f); fclose($h); ?> Check this out. Save this as test.php and run (you will have to display source in the browser to see actual output). Quote Link to comment https://forums.phpfreaks.com/topic/139052-redeclaring-class-dilemma/page/2/#findComment-728398 Share on other sites More sharing options...
drath Posted January 2, 2009 Author Share Posted January 2, 2009 Sorry, this was my own fault... something weird was happening and your direction to "view source" made me realize that it's going to echo the php directly, but in my view it was only showing some as plain text (comments broke some into html), the rest was in the source code. I forgot all about commands like strip_tags and htmlspecialchars - for whatever reason I just assumed echo would show me the output. Now that, that is solved, I can just parse it now instead of creating another file. DarkWater, since you asked for some example stuff, here would be an example of the content to parse: <?php class configclass { var $variable1 = '0'; var $variable2 = 'jce'; var $variable3 = '20'; } ?> Obviously I would like to get all the variables in the class to extend the usability of the application, but if it's easier I can just search for specific variables. Quote Link to comment https://forums.phpfreaks.com/topic/139052-redeclaring-class-dilemma/page/2/#findComment-728407 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.