# [patch] expose PHP version details as constants

- Thread: https://externals.io/message/35323
- Original archive: https://news-web.php.net/php.internals/35323
- Started by Pierre Joye on 2008-02-08T12:52:27+00:00
- Messages: 39
- Page 1 of 2: messages 1 to 25 (25 per page, add `?page=N` to the URL)
- Next page: https://externals.io/message/35323.md?page=2
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #35323 — Pierre Joye — 2008-02-08T12:52:27+00:00

URL: https://externals.io/message/35323#35323

Hi,

Testing the PHP version can be much easier and faster if the versions
details were exposed via the constants, like what we use internally.
This little patch expose what we have in php_version.h


#define `PHP_MAJOR_VERSION` 5
#define `PHP_MINOR_VERSION` 2
#define `PHP_RELEASE_VERSION` 6
#define `PHP_EXTRA_VERSION` "-dev"
#define `PHP_VERSION` "5.2.6-dev"  << already available as contant
#define `PHP_VERSION_ID` 50206

Patch against 5.2 attached.

Any objections?

Cheers,
-- 
Pierre
http://blog.thepimp.net | http://www.libgd.org

---

## #35333 — Stanislav Malyshev — 2008-02-08T18:42:58+00:00

URL: https://externals.io/message/35323#35333 · In reply to: #35323

Hi!

> Testing the PHP version can be much easier and faster if the versions
> details were exposed via the constants, like what we use internally.
> This little patch expose what we have in php_version.h

Looks ok, shouldn't harm anything.

-- 
Stanislav Malyshev, Zend Software Architect
stas@zend.com   http://www.zend.com/
(408)253-8829   MSN: stas@zend.com

---

## #35334 — David Coallier — 2008-02-08T19:52:08+00:00

URL: https://externals.io/message/35323#35334 · In reply to: #35323

> Hi,
>
> Testing the PHP version can be much easier and faster if the versions
> details were exposed via the constants, like what we use internally.
> This little patch expose what we have in php_version.h
>
>
> #define `PHP_MAJOR_VERSION` 5
> #define `PHP_MINOR_VERSION` 2
> #define `PHP_RELEASE_VERSION` 6
> #define `PHP_EXTRA_VERSION` "-dev"
> #define `PHP_VERSION` "5.2.6-dev"  << already available as contant
> #define `PHP_VERSION_ID` 50206
>
> Patch against 5.2 attached.
>
> Any objections?

Bla bla bla.. Commit the thing already :))

>
> Cheers,
> --
> Pierre
> http://blog.thepimp.net | http://www.libgd.org
>
> --
> 
> 
>



-- 
David Coallier,
Founder & Software Architect,
Agora Production (http://agoraproduction.com)
51.42.06.70.18

---

## #35336 — Marcus Boerger — 2008-02-09T13:39:40+00:00

URL: https://externals.io/message/35323#35336 · In reply to: #35323

Hello Pierre,
  yeah nice idea. I am wondering if you might want to add the cvs tag, too?
E.g.: PHP_TAG = 'PHP_5_3'

marcus

Friday, February 8, 2008, 1:52:27 PM, you wrote:

> Hi,

> Testing the PHP version can be much easier and faster if the versions
> details were exposed via the constants, like what we use internally.
> This little patch expose what we have in php_version.h


> #define `PHP_MAJOR_VERSION` 5
> #define `PHP_MINOR_VERSION` 2
> #define `PHP_RELEASE_VERSION` 6
> #define `PHP_EXTRA_VERSION` "-dev"
> #define `PHP_VERSION` "5.2.6-dev"  << already available as contant
> #define `PHP_VERSION_ID` 50206

> Patch against 5.2 attached.

> Any objections?

> Cheers,



Best regards,
 Marcus

---

## #35337 — Pierre Joye — 2008-02-09T13:42:55+00:00

URL: https://externals.io/message/35323#35337 · In reply to: #35336

Hi Marcus,


> Hello Pierre,
>   yeah nice idea. I am wondering if you might want to add the cvs tag, too?
> E.g.: PHP_TAG = 'PHP_5_3'


Oh right, nice idea :) It would be nice to have it as well. The idea
is to ease the tests writing and configuration detections.

Cheers,
-- 
Pierre
http://blog.thepimp.net | http://www.libgd.org

---

## #35344 — Jingcheng Zhang — 2008-02-10T08:39:28+00:00

URL: https://externals.io/message/35323#35344 · In reply to: #35337

Hello,
  Is there any chance that dirname(__FILE__) being exposed as a constant,
i.e. __DIRNAME__?



> Hi Marcus,
>
> 
> > […]
> too?
> > […]
>
>
> Oh right, nice idea :) It would be nice to have it as well. The idea
> is to ease the tests writing and configuration detections.
>
> Cheers,
> --
> Pierre
> http://blog.thepimp.net | http://www.libgd.org
>
> --
> 
> 
>
>


-- 
Best regards,
Jingcheng Zhang
Room 304, Dormitory 26 of Yuquan Campus, Zhejiang University
P.R.China

---

## #35345 — Jan Schneider — 2008-02-10T10:15:14+00:00

URL: https://externals.io/message/35323#35345 · In reply to: #35344

Zitat von Jingcheng Zhang <diogin@gmail.com>:

> Hello,
>   Is there any chance that dirname(__FILE__) being exposed as a constant,
> i.e. __DIRNAME__?

No. Constants are per request, dirname(__FILE__) is obviously  
different per file.

Jan.

-- 
Do you need professional PHP or Horde consulting?
http://horde.org/consulting/

---

## #35346 — Markus Fischer — 2008-02-10T10:53:46+00:00

URL: https://externals.io/message/35323#35346 · In reply to: #35345

Jan Schneider wrote:
> Zitat von Jingcheng Zhang <diogin@gmail.com>:
> 
> > […]
> 
> No. Constants are per request, dirname(__FILE__) is obviously different 
> per file.

That's not entirely true, isn't it? Think __FILE__ is per file, then we've 
__FUNCTION__, __LINE__, etc.

sincerely,
- Markus

---

## #35350 — Stanislav Malyshev — 2008-02-11T05:11:41+00:00

URL: https://externals.io/message/35323#35350 · In reply to: #35345

> > […]
> 
> No. Constants are per request, dirname(__FILE__) is obviously different 
> per file.

Actually, just as __FILE__, __LINE__, __CLASS__ etc. dirname(__FILE__) 
can be a parser constant. And if somebody produces a good name and a 
patch for it, I see no reason to reject it. Does anybody?
-- 
Stanislav Malyshev, Zend Software Architect
stas@zend.com   http://www.zend.com/
(408)253-8829   MSN: stas@zend.com

---

## #35361 — Lars Strojny — 2008-02-11T10:41:18+00:00

URL: https://externals.io/message/35323#35361 · In reply to: #35350

Hi Stanislav,

Am Sonntag, den 10.02.2008, 21:11 -0800 schrieb Stanislav Malyshev:
[...]
> Actually, just as __FILE__, __LINE__, __CLASS__ etc. dirname(__FILE__) 
> can be a parser constant. And if somebody produces a good name and a 
> patch for it, I see no reason to reject it. Does anybody?

For the name I would propose __DIR__, same as to __FILE__, __CLASS__,
__NAMESPACE__ etc. pp.

I tried to do it yesterday, but I need some advice on how to do it. So
far I need to add another token and an ST_IN_SCRIPTING entry. Basically
the quick hack would be to use zend_get_compiled_filename() in it. I
stuck how to extract the dirname. Should I use php_dirname() (which is
platform sensitive but this is considered inappropriate from what I
heard), should php_dirname() be moved? Or should I introduce another
hash table entry for the current dirname?

cu, Lars

---

## #35368 — Lars Strojny — 2008-02-11T11:51:00+00:00

URL: https://externals.io/message/35323#35368 · In reply to: #35350

Hi,

Am Sonntag, den 10.02.2008, 21:11 -0800 schrieb Stanislav Malyshev:
[...]
> Actually, just as __FILE__, __LINE__, __CLASS__ etc. dirname(__FILE__) 
> can be a parser constant. And if somebody produces a good name and a 
> patch for it, I see no reason to reject it. Does anybody?

So here we are. The following patch[1] adds support for the constant
__DIR__ which is dirname(__FILE__).

[1] http://lars.schokokeks.org/php/dir-constant-2.diff

cu, Lars

---

## #35375 — Pierre Joye — 2008-02-11T14:20:50+00:00

URL: https://externals.io/message/35323#35375 · In reply to: #35336

> Hello Pierre,
>   yeah nice idea. I am wondering if you might want to add the cvs tag, too?
> E.g.: PHP_TAG = 'PHP_5_3'


I'll commit the patch later today, I think PHP_BRANCHE sounds better
than PHP_TAG, or PHP_CVS_TAG (but if we move away from CVS? :-D )


Ilia, I know you see no use of this but is it ok to apply it to 5.2 too?

Cheers,
-- 
Pierre
http://blog.thepimp.net | http://www.libgd.org

---

## #35376 — Pierre Joye — 2008-02-11T14:42:24+00:00

URL: https://externals.io/message/35323#35376 · In reply to: #35375

> 
> > […]
>
>
> I'll commit the patch later today, I think PHP_BRANCHE sounds better
> than PHP_TAG, or PHP_CVS_TAG (but if we move away from CVS? :-D )


Typo, I meant PHP_BRANCH

-- 
Pierre
http://blog.thepimp.net | http://www.libgd.org

---

## #35377 — Lars Strojny — 2008-02-11T15:25:38+00:00

URL: https://externals.io/message/35323#35377 · In reply to: #35368

Hi,

Am Montag, den 11.02.2008, 12:51 +0100 schrieb Lars Strojny:
[...]
> [1] http://lars.schokokeks.org/php/dir-constant-2.diff

Updated version. Moved and renamed php_dirname() to zend_dirname() to
not use PHP internals in the Zend Engine. Fixed a memory leak and added
the TSRM-includes to have some macros/constants defined.

Comments? Critics?

cu, Lars

---

## #35378 — Pierre Joye — 2008-02-11T16:15:07+00:00

URL: https://externals.io/message/35323#35378 · In reply to: #35377

> Hi,
>
> Am Montag, den 11.02.2008, 12:51 +0100 schrieb Lars Strojny:
> [...]
> > […]
>
> Updated version. Moved and renamed php_dirname() to zend_dirname() to
> not use PHP internals in the Zend Engine. Fixed a memory leak and added
> the TSRM-includes to have some macros/constants defined.
>
> Comments? Critics?

I did not see the zend_dirname usage (wrong link?) and did not find
either this function/macro.

I slightly modified it to avoid too much strlen and to do not process
the string if there is nothing to process. Please find my version of
your patch as attachment.

Thanks for your work!
-- 
Pierre
http://blog.thepimp.net | http://www.libgd.org

---

## #35379 — Lars Strojny — 2008-02-11T16:25:01+00:00

URL: https://externals.io/message/35323#35379 · In reply to: #35378

Hi Pierre,

Am Montag, den 11.02.2008, 17:15 +0100 schrieb Pierre Joye:
[...]
> I did not see the zend_dirname usage (wrong link?) and did not find
> either this function/macro.
> 
> I slightly modified it to avoid too much strlen and to do not process
> the string if there is nothing to process. Please find my version of
> your patch as attachment.

I forgot to add the link, I'm so sorry.
http://lars.schokokeks.org/php/dir-constant-4.diff

cu, Lars

---

## #35382 — Ilia Alshanetsky — 2008-02-11T16:35:30+00:00

URL: https://externals.io/message/35323#35382 · In reply to: #35375

We spoke about this via IM, but its only fair that the answer be  
provided via a mailing list as well.

 From my standpoint this is a feature, although a minute one and 5.2  
is not in a feature mode right now, we have 5.3 and PHP 6 for that.  
Secondly these constants are of dubious value (besides making code  
slightly shorter) since nearly everything they offer can already be  
done via the existing `PHP_VERSION` constant and version_compare. Big  
version checks like the ones for 5 vs 6 you don't even need version  
compare:
if (PHP_VERSION > 6) etc...

Therefor, for these two reasons I do not believe we need these  
constants in 5.2 branch.



> 
> > […]
>
>
> I'll commit the patch later today, I think PHP_BRANCHE sounds better
> than PHP_TAG, or PHP_CVS_TAG (but if we move away from CVS? :-D )
>
>
> Ilia, I know you see no use of this but is it ok to apply it to 5.2  
> too?
>
> Cheers,
> -- 
> Pierre
> http://blog.thepimp.net | http://www.libgd.org

Ilia Alshanetsky

---

## #35383 — johannes@php.net — 2008-02-11T16:40:45+00:00

URL: https://externals.io/message/35323#35383 · In reply to: #35376

Pierre,


> 
> > […]
> 
> 
> Typo, I meant PHP_BRANCH

Yes that name is fine, bunt wondering: When/Where do you get this
information and where from? What's the impact for build
snapshots/releases? Afaik the scripts for that work on cvs exports where
that information isn't available anymore.

johannes

---

## #35384 — Pierre Joye — 2008-02-11T16:42:48+00:00

URL: https://externals.io/message/35323#35384 · In reply to: #35379

Hi Lars,


> Hi Pierre,
>
> Am Montag, den 11.02.2008, 17:15 +0100 schrieb Pierre Joye:
> [...]
> > […]
>
> I forgot to add the link, I'm so sorry.
> http://lars.schokokeks.org/php/dir-constant-4.diff

Looks better :)

I did not test it but it looks good. Did you run the tests suite?

+	dirname = estrndup(filename, strlen(filename));
+	zend_dirname(dirname, strlen(dirname));

One strlen can be dropped here.

Grüße,
-- 
Pierre
http://blog.thepimp.net | http://www.libgd.org

---

## #35385 — Pierre Joye — 2008-02-11T16:51:35+00:00

URL: https://externals.io/message/35323#35385 · In reply to: #35383

> Pierre,
>
> 
> > […]
>
> Yes that name is fine, bunt wondering: When/Where do you get this
> information and where from? What's the impact for build
> snapshots/releases? Afaik the scripts for that work on cvs exports where

Good point, I did not check the CVS doc before and can't find how to
get it in the same way than $Id$. Marcus? :)

-- 
Pierre
http://blog.thepimp.net | http://www.libgd.org

---

## #35386 — Lars Strojny — 2008-02-11T16:55:40+00:00

URL: https://externals.io/message/35323#35386 · In reply to: #35384

Hi Pierre,

Am Montag, den 11.02.2008, 17:42 +0100 schrieb Pierre Joye:
[...]
> Looks better :)

Thank you!

> I did not test it but it looks good. Did you run the tests suite?
> 
> +	dirname = estrndup(filename, strlen(filename));
> +	zend_dirname(dirname, strlen(dirname));
>
> One strlen can be dropped here.

Ah, good hint. See  http://lars.schokokeks.org/php/dir-constant-5.diff
for the corrected version.

cu, Lars

---

## #35387 — Pierre Joye — 2008-02-11T16:58:04+00:00

URL: https://externals.io/message/35323#35387 · In reply to: #35386

> Hi Pierre,
>
> Am Montag, den 11.02.2008, 17:42 +0100 schrieb Pierre Joye:
> [...]
> > […]
>
> Thank you!
>
> > […]
>
> Ah, good hint. See  http://lars.schokokeks.org/php/dir-constant-5.diff
> for the corrected version.

One more thing:

const size_t filename_len = strlen(filename);

and it should be good. Stan, looks ok for you?

-- 
Pierre
http://blog.thepimp.net | http://www.libgd.org

---

## #35388 — Lars Strojny — 2008-02-11T17:04:54+00:00

URL: https://externals.io/message/35323#35388 · In reply to: #35387

Hi,

Am Montag, den 11.02.2008, 17:58 +0100 schrieb Pierre Joye:
[...]
> One more thing:
> 
> const size_t filename_len = strlen(filename);
> 
> and it should be good. Stan, looks ok for you?

Done: http://lars.schokokeks.org/php/dir-constant-6.diff

cu, Lars

---

## #35389 — johannes@php.net — 2008-02-11T17:27:08+00:00

URL: https://externals.io/message/35323#35389 · In reply to: #35385

> > […]
> 
> Good point, I did not check the CVS doc before and can't find how to
> get it in the same way than $Id$. Marcus? :)

No, there is no such keyword which offers this information. The only way
to get it would be to inject it from the scripts ... but I guess that
just leads to trouble afterward. And I don't see much need for the
branch info anyhow ...

johannes

---

## #35397 — Stanislav Malyshev — 2008-02-11T21:25:30+00:00

URL: https://externals.io/message/35323#35397 · In reply to: #35388

> > […]
> 
> Done: http://lars.schokokeks.org/php/dir-constant-6.diff

I'm not sure what happens if zend_dirname returns 0, also what happens 
if this constant is used in eval(), stream of anything else with 
non-canonical filename? Except that, looks ok.
Some tests won't hurt though :)
-- 
Stanislav Malyshev, Zend Software Architect
stas@zend.com   http://www.zend.com/
(408)253-8829   MSN: stas@zend.com

---

Next page: https://externals.io/message/35323.md?page=2
