Page 1 of 1

Namespace in PHP file error

PostPosted: February 28th, 2013, 10:44 am
by strublos
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

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

Re: Namespace in PHP file error

PostPosted: February 28th, 2013, 1:56 pm
by Jakub Misek
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!

Re: Namespace in PHP file error

PostPosted: February 28th, 2013, 2:45 pm
by strublos
Can you post easy example of calling .NET class function from PHP file?
Something like
Code: Select all
use System;
$rnd = new Random();//create object Random from System namespace
echo $rnd.Next();


Thank you

Re: Namespace in PHP file error

PostPosted: February 28th, 2013, 3:17 pm
by strublos
I got It!

Code: Select all
<?php
$rnd = new System\Random;
echo $rnd->Next();
?>


Tips: print_r(get_declared_classes());

Re: Namespace in PHP file error

PostPosted: February 28th, 2013, 3:29 pm
by Jakub Misek
Yes, you can also use 'use' keyword to shorten your code:
Code: Select all
use System\Random;
$rnd = new Random;