Namespace in PHP file error
5 posts
• Page 1 of 1
Namespace in PHP file error
Hi, I try to move PHP application from Linux/Apache to Windows/IIS.
I setup IIS and I can call PHP file over internet browser, thats OK.
When I try use .NET features in PHP file
I got this error
Its possible to do this?
In web.config I have this section
Thank you for any suggestion
I setup IIS and I can call PHP file over internet browser, thats OK.
When I try use .NET features in PHP file
- Code: Select all
<?php
import namespace System;
?>
I got this error
- Code: Select all
CompileError (2014): Syntax error: unexpected token 'namespace' in C:\inetpub\wwwroot\webApplication\test.php on line 4, column 10.
Its possible to do this?
In web.config I have this section
- Code: Select all
<phpNet>
<compiler>
<set name="LanguageFeatures">
<add value="PhpClr" />
</set>
</compiler>
<classLibrary>
<add assembly="mscorlib" />
<add assembly="System, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<add url="phpLib\PhpNetPDO.dll" />
<add url="phpLib\PhpNetMsSql.dll" />
</classLibrary>
</phpNet>
Thank you for any suggestion
- strublos
- Posts: 3
- Joined: February 25th, 2013, 12:39 pm
Re: Namespace in PHP file error
Hi,
'import namespace' is deprecated syntax used in early versions of Phalanger; in times when PHP did not have specifications for namespaces yet.
This has been removed, and Phalanger used legacy PHP syntax for namespaces now. Sadly PHP does not support importing of namespacing, just so-called 'aliasing'.
Take a look on 'use' keyword in PHP.
Thanks!
'import namespace' is deprecated syntax used in early versions of Phalanger; in times when PHP did not have specifications for namespaces yet.
This has been removed, and Phalanger used legacy PHP syntax for namespaces now. Sadly PHP does not support importing of namespacing, just so-called 'aliasing'.
Take a look on 'use' keyword in PHP.
Thanks!
Jakub Misek │ DEVSENSE s.r.o. | @misekjakub │ jakub@devsense.com │
-
Jakub Misek - Posts: 2092
- Joined: January 4th, 2012, 2:42 pm
- Location: Prague
Re: Namespace in PHP file error
Can you post easy example of calling .NET class function from PHP file?
Something like
Thank you
Something like
- Code: Select all
use System;
$rnd = new Random();//create object Random from System namespace
echo $rnd.Next();
Thank you
- strublos
- Posts: 3
- Joined: February 25th, 2013, 12:39 pm
Re: Namespace in PHP file error
I got It!
Tips: print_r(get_declared_classes());
- Code: Select all
<?php
$rnd = new System\Random;
echo $rnd->Next();
?>
Tips: print_r(get_declared_classes());
- strublos
- Posts: 3
- Joined: February 25th, 2013, 12:39 pm
Re: Namespace in PHP file error
Yes, you can also use 'use' keyword to shorten your code:
- Code: Select all
use System\Random;
$rnd = new Random;
Jakub Misek │ DEVSENSE s.r.o. | @misekjakub │ jakub@devsense.com │
-
Jakub Misek - Posts: 2092
- Joined: January 4th, 2012, 2:42 pm
- Location: Prague
5 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 12 guests