Why does xpath query syntax vary in lower version of php - php

I have been developing on my test server which is PHP 5.5 and used an xpath query of this structure:
$year = $this->xml->xpath("//field[#label='Year']");
$year[0]['value'];
And all works perfect but as sson as I move it to the live server which is php 5.4 all my xpath queries would break. I am just wondering if anyone out there could give me some insight as to why or how to overcome this problem without upgrading php. I am guessing something is not enabled on my live site other than xpath that should be.

Compare versions of SimpleXml on server and the testing environment. (use phpinfo(); for that)
I would also advice you to step over to DOMDocument which I have noticed is actually more reliable. Otherwise please post your original xml so we can take a look for possible problems.

Related

Application built on joomla displaying raw data on localhost

m having a strange problem never faced it before and tried every thing and i mean everything but no luck at all.
What happened was i downloaded the application source code built on joomla 1.7 via ftp from the live server and deployed it on my localhost and configured it correctly. Now what happened is it displaying some sort of raw data all over the browser window, attached is the screenshot.
Please guys its been 5 days since i stuck in this mess any help will be highly appreciated
Thanks in advance
Maybe you have installed an extension, which supports distribution of PHP code as binary code? There exist different extensions to PHP, which support this kind of functionality. Probably the most widespread is Zend Guard. To execute a script which was encrypted by this software your PHP needs to load the free loader extension provided by Zend. If your server has loaded this extension and your localhost does not, the output might be something like you encounter.
Your first step should be to compare the output of phpinfo of both servers. If Zend Guard (or a similar extension) is loaded on your production server and not on your localhost, this might be the problem. Next step should involve taking a look at the PHP files and search for one which contains lots of unreadable characters. If this seems unreasonable to you, you might as well just install Zend Loader and see if it works then, which might be less work.

Can't access model data using Model name in CakePHP 2.x with PHP version 5.3.27

On my development server, I installed PHP (5.5), MySQL and Apache. The hosting company only supports up to PHP version 5.3.27. I don't really work in PHP, often so I might be missing something obvious here, but my problems are the following:
CakeSession::read('User.stuff')['more_stuff']; // works on 5.5
CakeSession::read('User.stuff')['more_stuff']; // syntax error on 5.3... wat?!
I managed to fix the above issue by assigning CakeSession::read('User.stuff') to a temp variable, and then accessing more stuff with $tmp['more_stuff'].
However, I have a bigger problem. I can't seem to access model names by their model name in arrays returned from databases. Namely, the following code stopped working:
$some_model['ModelName']['model_field']; //works on 5.5
$some_model['ModelName']['model_field']; //warning about 'ModelName' being a non-existant index.
When I try $some_model[0]['model_field'] it works just fine.
Cheers!
EDIT: Ok, turns out < PHP 5.4 doesn't support subscripting return values. Still weird, but it explains the first problem.
As you found out, array dereferencing with function/method call expressions is only supported as of PHP 5.4, nothing special about it, it's simply a feature of newer PHP versions.
Your other problem is most probably not that string indices magically don't work anymore, but simply that the structure of the array you are accessing is different.
Where this difference might stem from? Pretty hard to tell without any context. You should provide some code that can be used to reproduce your situation, and you should also do some more debugging on your own, trace back the function call flow and check at which point the data becomes different.

PHP string on Host server from DW CS6

I am new to PHP and teaching myself. I have built some training sites but I am having a problem when I load the files from Dreamweaver 6 to my internet hosting server.
The site works and displays fine locally. But when I load the site files on the hosting server and try to view the site it gives me an error coming from my server strings. If I edit the code on the server file(see below) I can make it work fine.
Is there a setting on DW that I need to do to make it compatible and not have to be edited once I put the files to the host server? Or is it a version problem? I am using DW CS6 and PHP version 5.4.3
My hosting server is using PHP 5.3.
Here what the code looks like....
Existing code that comes from Dreamweaver - "mysql_select_db($database_ique22, $ique22)";
On server if I edit to the following it clears the error - "mysql_select_db($database_ique22)";
Thanks for any advice.....
I'm not familiar with what Dreamweaver implements as far as helping with PHP, but if you're really interested in learning PHP I'd ditch Dreamweaver altogether. The PHP.net docs are fantastic and an editor like Sublime Text 2 will work much better for you without doing confusing things.
In any case, the second parameter of mysql_select_db is the link identifier (used generally if you need to connect to multiple MySQL servers). It should only throw an error if $ique22 is not set to a MySQL connection using something along the lines of $ique22 = mysql_connect("server","user","pass");
One thing to keep in mind is that the mysql_ function set is deprecated and you'll want to switch to using mysqli.
http://php.net/manual/en/book.mysqli.php

Migrating php code from 5.2 to 5.3

I was asked to help getting a website that was running with 5.2 php code, to work on a 5.3 php server. The site is big, and I can't see the errors that would appear normally when a site isn't working.
I've tried to use the Search and replace function that Dream Weaver has, and simply use it all over the website. But the problem is that I only want to replace functions in PHP documents, and not in js files. When i use Search and replace, in Dreamweaver, it overwrites the js files aswell, and that would cause more errors. Because there's A LOT of files that i have to go through, it would take me a lot of time if i had to go through it manually.
I figured this must be a problem that a lot of firms experiance, so there must be ways to handle this without it being a bigger hassle.
Anybody out there who could help me out ? Any help is much appreciated!
Regards,
Mathias
Check out the official guide about Migrating from PHP 5.2.x to PHP 5.3.x
most existing PHP 5 code should work without changes, but make sure error-reporting is enabled to get some idea of what is going wrong .
I would recommend the use of sed from command line. It is most likely the fastest and most powerful find/replace utility available for LAMP developers.
http://www.grymoire.com/Unix/Sed.html
Dont worry about it! If your code works in php->5 for the most part it will work just fine. 5.3 offers a plethora of options but no doubt your not using them.

is there any way to find php application is compatible with particular version or not

I have one big php application running on php 4 but I want to move this application on php 5.2 but I am not sure whether it's all functionally work on it or not as I don't want to test full application again. So I want to know is there a way to find out compatibility of application with php versions.
PHP5 come with major changes, I don't think there's such an automated way to check compatibility out there..
You'll have to check all files manualy. use batch file text seach (and replace?) tools to look for functions, classes etc.
here's your guide to start
Unfortunately, you're going to have to test it. You can at least use the PHP changelog as a bit of a checklist to see if any code in application is affected.
PHP 4 to PHP 5 was a pretty huge leap; it's probably a safe bet your app was affected even before you go through testing.
You can use online tool for checking syntax compatibility of your code php 4 and php 5.2,5.3. For manual checking read Migrating from PHP 4 to PHP 5.0.x .

Categories