Usable in both PHP5 and PHP7

I like to make my code usable in both PHP5 and PHP7
The would-be code below doesn’t work correctly, but I hope it show what I want.

Would-be code

if (phpVersion =< PHP5)  {

    if(session_id() == '') {
	// Initiate the session start here
    } 

} else {

if(session_status() == PHP_SESSION_NONE) {
	// Initiate the session start here
}

}

Did you try these two proposed solution *one is remmed out):

Edit:
Please explain why your code “doesn’t work correctly”…

…also and far more importantly the supplied code produces syntax errors which should be searched and rectifed before posting.

why are you throwing random constants and operators around? that should at least raise a syntax error.

Which version of PHP 5? According to the manual, session_status() can be used from PHP 5.4 and newer

1 Like

May I ask why? Php 5 has reached end of life and is unsupported. Version 5.0 reached end of life over 14 years ago and 5.6, the last 5.x version reached EOL 10 months ago. Heck, even version 7.0 has already reached end of life and 7.1 active support ended 11 months ago and 7.2 only has 17 days left of active support.

2 Likes

PHP Version 5.2.12.

I have two servers, The old one is 5.2.12, and The new one is 7.2.24

I am on the way of migrating the major code of old one to new one.
when I find better code during migration, I am modified the old code to the better code.

The code for PHP5.2.12 in PHP7.2.24 will be depreciated.

I tried to make what I want clear, but I am afraid it is possibly lead misunderstanding.

I provided some of the code to the OP. I didn’t want to land both of the codes on the same version where it may be a bit confusing to the OP. So I just said 5.5 and higher for session_status(). But it is indeed supported on 5.4 as well.

It should actually be

PHP_VERSION <= '5.4'
1 Like

Thanl you, spaceshiptroope

Ok, so this is where version control comes in (GIT). You have one branch for old PHP server and another branch for new PHP server. Never the twain shall meet.*

* Used to suggest that two things are too different to coexist

I don’t know the correct reason of it at the moment.
I might have too short experience with the coexist to understand how inconvenient it is.
With keep the quote above in my mind, I’ll try to migrate old project with coexist till I experience to know the correct reason of it.

It will take time, but I understand the procedures at least .
If the direction is on the right, It’s okay that I go slow.

Anyway, I’ll keep the quote above in my mind.

This will be another challenge for me.
I feel having long way to go.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.