473,473 Members | 1,755 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Syntax checking with create_function()

Hi all,

The thing I'm doing just now uses create_function(). This works fine
provided I don't do something silly in the code I am trying to incorporate.

Is there any way I can check the syntax (like `php -l sript.php`). I know
that there is php_check_syntax() in PHP 5 but it needs a file & I'm still
on v 4.x.

I guess I could create a temporary file and try `php -l $tempfile` but
there's the complications of knowing what OS is on the machine where it's
running, also just because it has mod_php doesn't necessarily mean it has
the standalone.

I tried the code below, but it seems to only throw errors when you try to
execute the function which got created.

TIA,

C.

function lister_check_errors($errno, $errstr, $errfile, $errline)
{
global $lister_embed_errors;
$errdesc=array( FATAL=>'FATAL', ERROR=>'ERROR', WARNING=>'WARNING');
$errtype=$errdesc[$errno];
if ($errtype=='') {
$errtype="UNKNOWN";
}
$lister_embed_errors="$errtype [$errno]: $errstr<br />\n&nbsp; in line
$errline";
}
function lister_check_syntax($code,$params)
{
global $lister_embed_errors;
$lister_embed_errors='';
$errhandler=set_error_handler('lister_check_errors ');
if ($errhandler===false) {
return("set_error_handler() returned false");
}
// this doesn't detect the errors - you need to run the function
// to prove it! But this may modify the thing we are trying to list
$fn=create_function($params,$code);
set_error_handler($errhandler);
return($lister_embed_errors);
}

Jul 17 '05 #1
1 1781
Colin McKinnon wrote:

I tried the code below, but it seems to only throw errors when you try to
execute the function which got created.


Actually, it is throwing the errors - just not the way I thot it would. Back
to the drawing board.

C.
Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: TheKeith | last post by:
Hi, I'm just learning php now for the first time and I'm having a little trouble understanding something. In the following example: ...
3
by: Ian.H | last post by:
Hi all, I'm trying to write a PHP colour parser and after various attempts, something, somewhere trips it over. Some details: String to parse: $origString = '^1foo^5bar';
2
by: George Sakkis | last post by:
I downloaded the latest Komodo (3.1) and configured it for python 2.4 so that it doesn't show decorators and genexps as syntax errors, but background syntax checking doesn't seem to work at all for...
4
by: nonzero | last post by:
I was hoping someone could explain the Syntax of the second argument of the bind() function. bind(sockfd, (struct sockaddr *)&my_addr, sizeof(struct sockaddr)); .....................(struct...
1
by: Karim Nassar | last post by:
I am writing functions and I find it curious that CREATE FUNCTION does not do syntax checking. Example: test=# CREATE FUNCTION foo(INTEGER) RETURNS BOOLEAN test-# AS 'this is total crap'...
21
by: Dmitry Anikin | last post by:
I mean, it's very convenient when default parameters can be in any position, like def a_func(x = 2, y = 1, z): ... (that defaults must go last is really a C++ quirk which is needed for overload...
0
by: Dima Vidmich | last post by:
Recently I think about some sort of safe includes which will not fail if parse error happened. And many different sourses said that this is imposible without some non standard modules and without...
8
by: lawrence k | last post by:
Just noticed this for the first time: http://us2.php.net/manual/en/function.create-function.php Anyone know if PHP supports enclosures, like Javascript or Ruby? I've always assumed PHP lacked...
4
by: FM | last post by:
Hi there: My question is about checking my sql-syntax against DB2UDB V9 throug JDBC 2.0 Is there a way to check my syntax,for example "select * from T1"? Thank you for your help. Regards,
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.