dump and die dd($variable) displays always expanded - php

When I use dump and die dd($variable) in laravel 9 / php 8.0.2 , the response is always expanded, and I cannot colapse it, clicking on the arrow does nothing, is this a setting?

Related

How to call a php file with arguments from VBA for Mac? Equivalent of VBA.createObject("wscript.shell") on Mac?

Still in need of help :)
I'm trying to adapt the following chunk of code to VBA for Mac (as the final implementation has to be on Mac):
Dim ws as Object
Dim result as String
Set ws = VBA.CreateObject("wscript.shell")
cd = "php " & dirPHP & "\verificar.php " & FileName
result = ws.Run(cd)
Set ws = Nothing
It runs perfectly on Windows, but when trying to adapt it for Mac I'm encountering many problems.
What I am basically doing on the previous chunk is calling a PHP file that takes the first argument (in this case, FileName) and calls the verify function, returning some values.
The thing is that there are some posts explaining how to do this, but I have seen no examples on how to do it for PHP, and especially for PHP passing an input argument.
This is what I've tried so far:
result = AppleScriptTask("PHPCommand.applescript", "PHPCommandHandler", FileName)
e = "php " & dirPHP & "/verificar.php " & FileName cd = "do shell script """ & e & """" result = MacScript(cd)
(On the Mac Terminal I am able to run the PHP file fine, with the resulting "e" string).
And some other fruitless things, like the shell() function, or some other user-defined functions (I saw someone defined a "system()" function). I also tried many ways of putting the double and simple quotes, and simplified the path to the PHP file (dirPHP) and the path + filename of the argument (FileName) by removing all blank spaces and thus the need of using additional quotes.
Please help me! I'd be really grateful, as yesterday I spent the whole day on this and I can't keep wasting time on something that is so simple on Windows... But I have to do it on Mac.
Thanks so much!!!
Use the VBA Shell function.
Shell
Runs an executable program and returns a Variant (Double) representing
the program's task ID if successful; otherwise, it returns zero.
Syntax
Shell(pathname, [ windowstyle ])

bash script not executing mysql command with values passed as variables

I am modifying a set of bash scripts that process video files and reports the processing steps to a mysql database (here is the original code in question).
The function that does the database reporting is called from the main processing script and looks like this in the original:
_report_to_db(){
if [ "${REPORT_TO_DB}" = "Y" ] ; then
echo "INSERT IGNORE INTO tableA (objectIdentifierValue,object_LastTouched) VALUES ('${MEDIA_ID}',NOW()) ON DUPLICATE KEY UPDATE object_LastTouched = NOW()" | mysql --login-path="${LOGIN_PROFILE}" "${DB_NAME}" 2> /dev/null
_db_error_check
fi
}
Since the scripts are meant to be run directly from the command line, when you run them that way it works fine. But I'm running them via php from a web interface and there's some shenanigans going on with the quoting/escaping of whitespace and/or variables.
For instance, the script breaks on the whitespace after ...| mysql and it thinks I'm trying to run mysql as root without a password and totally ignores the --login-path and the other stuff I'm piping to it.
When I call mysql from a variable like so:
_report_to_db(){
if [ "${REPORT_TO_DB}" = "Y" ] ; then
SQL_ARRAY=(INSERT IGNORE INTO tableA (columnA,lastTouched) VALUES ("${SOME_PASSED_VALUE}",NOW()) ON DUPLICATE KEY UPDATE object_LastTouched = NOW();)
MYSQL_COMMAND_ARRAY=(mysql --login-path="${LOGIN_PROFILE}" -e "${SQL_ARRAY[#]}" "${DB_NAME}")
echo "$(${MYSQL_COMMAND_ARRAY[#]})"
_db_error_check
fi
}
... I am able to log into mysql correctly but the SQL query is ignored (when it echos the result you get the standard MySQL --help output.
So far I have tried all kinds of variations on quoting, escaping, referencing the query as a separate string variable, as an array (as you see here).
What is also not helpful is that the original _db_error_check() function only checks the value of the pipe exit status. So if the pipe is ok, but there's a problem further down the path, it fails silently.
_db_error_check(){
if [ "$?" != "0" ] ; then
# reports an error if the pipe exit value ≠ 0
else
# everything is ok! even if there was a mysql error
fi
}
This is not a file or database permissions issue (already triple checked that). Are there quotes or some other stupid thing that I am missing?? Thanks! Oh, I am running OSX El Capitan.
UPDATE
Lol, I was going to post the PHP that calls the script and then I remembered that the PHP is actually calling a Pyhton script that does some other processing too, and that is what calls the bash script. Here it all is:
PHP
$command = escapeshellcmd("/usr/local/bin/python3 /Users/user/path/to/ingest.py " . $user . " 2>&1");
while (# ob_end_flush());
$proc = popen($command, 'r');
echo '<pre>';
while (!feof($proc))
{
echo fread($proc, 4096);
# flush();
}
echo '</pre>';
PYTHON
for item in os.listdir(ingestDir):
if not item.startswith("."):
filePath = os.path.abspath(ingestDir+"/"+item)
fileNameForMediaID = os.path.splitext(item)[0]
try:
ingest = subprocess.Popen(['/usr/local/bin/ingestfile','-e','-u',user,'-I',filePath,'-m',fileNameForMediaID])
ingest.wait()
os.remove(filePath)
except IOError as err:
print("OS error: {0}".format(err))
UPDATE 2
I think this might actually be a weird quirk of my installation (go figure). Using mysql --login-path=myDbUser [etc...] from a shell on my host machine I keep getting the error ERROR 1045 (28000): Access denied for user 'ADMIN'#'localhost' (using password: NO) where the client user is ADMIN and I am trying to login as myDbUser.
I actually uninstalled and reinstalled mysql (via Homebrew) and still have the same results. Using a different machine (running Sierra, but the same mysql version) I can run the above shell command successfully and log into mysql as the target user.
Also on the host machine, I can sudo -u _www zsh and run the command as the Apache user (which is the user running the whole show) without a problem. SO WHY IS IT NOT RUNNING CORRECTLY EITHER IN THE SCRIPT OR EVEN RUN FROM SHELL AS MY MAIN CLIENT USER???
Any ideas? $PATH is identical in all cases mentioned above. Same ~/.mylogin.cnf setups. Is there anything else stupid obvious I missed?
You need to use indirect expansion here:
echo "$(${MYSQL_COMMAND_ARRAY[#]})"
the man says:
If the first character of parameter is an exclamation point (!), and
parameter is not a nameref, it introduces a level of variable
indirection. Bash uses the value of the variable formed from the rest
of parameter as the name of the variable; this variable is then
expanded and that value is used in the rest of the substitution,
rather than the value of parameter itself. This is known as indirect
expansion. If parameter is a nameref, this expands to the name of the
variable referenced by parameter instead of performing the complete
indirect expansion. The exceptions to this are the expansions of
${!prefix*} and ${!name[#]} described below. The exclamation point
must immediately follow the left brace in order to introduce
indirection.
${!name[#]}
${!name[*]}
If name is an array variable, expands to the list of array indices
(keys) assigned in name. If name is not an array, expands to 0 if name
is set and null otherwise. When ‘#’ is used and the expansion appears
within double quotes, each key expands to a separate word.
PS: If I may put forward a piece of my personal opinion, having a chain of php -> python -> bash is the worst coding style one can ever met, you may want to rewrite it into single langue so it will be easier to track down further issues at least.

PHP PDO Incorrect syntax near GO, MSSQL & sql_srv [duplicate]

This question already has answers here:
Incorrect syntax near 'GO'
(9 answers)
Closed 6 years ago.
I am having trouble executing a long MSSQL script using PHP and PDO.
It contains some batch statements separated by GO. The script runs if its executed in Management Studio.
I have ensured line endings are not causing the issue.
I have also tried to enable beginTransaction() before the request is executed. Which returns the following error: SQLSTATE[IMSSP]: This function is not implemented by this driver.
I'm using IIS8 and PHP 5.4.16 and the pdo_sqlsrv driver
First part of the script:
USE foo;
IF object_id(N'ToBit', N'FN') IS NOT NULL
DROP Function dbo.ToBit
GO
CREATE FUNCTION dbo.ToBit(
#InputString varchar(250)
)
RETURNS BIT
AS BEGIN
DECLARE #OutputBit BIT
SET #OutputBit = CASE
WHEN (#InputString = 'yes') THEN 1
WHEN (#InputString = 'true') THEN 1
WHEN (#InputString = '1') THEN 1
ELSE 0
END
RETURN #OutputBit
END
Is it down to the driver? I can't see why GO would require beginTransaction() being called? Other than that I'm out of ideas.
Update: I think I might have found an answer here. Will update if I find a soloutio.
Incorrect syntax near 'GO'
Have found an answer here by Jon Galloway
GO isnt valid T-SQL, its a command used by SQLCMD and other utilities, and parsed before execution.
It looks like there are a few options.
1) Execute the script using OSQL / command line
2) Split the script at each GO separator, then run them in sequence
3) If using .NET you can look at using SQL Server Management Objects:
Server.ConnectionContext.ExecuteNonQuery()
This parsers T-SQL statements and "gets" the GO statement as a batch separator.

Memcached - Test with telnet - strange result

I'm storing my PHP session with memcached using $memcached->set('sessions/'.$sessionId, json_encode($_SESSION), 1000); which works just fine within PHP. But if I open a connection with telnet and type get sessions/123123 it results in strange signs like Â$Áª"P«UMέuë].ùç where I expect to have some JSON string.
Any idea on that would be much appreciated.

Which PHP version is required for str_split?

I relogin to my server in dreamhost and test some scripts.And I found I couldn't use str_split. Message of Undefined function was given.I checked the version in the server and its PHP Version is 5.2.12.And I just wonder which version is required?Thanks.
Testcode:
<?php
$arr = str_split("lsdjflsdjflsdjflsdjfl");
print_r($arr);
?>
Message:
Fatal error: Call to undefined function: str_split() in /test.php on line 3
Edit #Justin Johnson
I checked the server's system directory,and I found there are two versions of PHP in Dreamhost.In user's webroot,file will be parsed by PHP5 and that's why I got php 5.2.12 by putting a phpinfo.php in the webroot.And if php files are ran in command line directly using php test.php,another php version which is 4.x worked.That's the reason I got an error.When I use
/usr/local/php5/bin/php test.php
Everything is fine.
Rather than use str_split, it's usually much easier to iterate through the characters of the string directly:
$s="abc";
$i=0;
while(isset($s[$i])) {
echo $s[$i++]." ";
}
see?
First off: The PHP documentation will always say what version is required for every function on that function's documentation page directly under the function name.
It is possible that an .htaccess file is somewhere in your path and is causing a previous version (<5) of PHP to be used. To double (or triple) check to make sure that you are running in the proper PHP version, place this code above the line where you call str_split
echo "version:", phpversion(),
"<br/>\nstr_split exists? ",
function_exists("str_split") ? "true" : "false";
However, as shown by Col. Shrapnel, it is not necessary to convert a string to an array of individual characters in order to iterate over the characters of that string. Strings can also be iterated over using traditional iteration methods, thus making the call to str_split unnecessary and wasteful (unless you need to segment the string into fixed length chunks, e.g.: str_split($s, 3))
foreach ( str_split($s) as $c ) {
// do something with character $c
}
can be replaced by
$s = "lsdjflsdjflsdjflsdjfl";
for ( $i=0; isset($s[$i]); ++$i ) {
// do something with character $s[$i]." ";
}
which is equally, if not more clear.
According to dreamhost wiki, you need to switch to php5 manually from control panel, if you created your domain before 2008 sept.
http://wiki.dreamhost.com/Installing_PHP5#Using_DreamHost.27s_PHP_5
PHP 5 was added to all plans by
DreamHost as of June 2005. As of
September 2008, support for PHP4 was
discontinued, so you can no longer
switch back to PHP 4 from PHP 5 from
the panel.
If you haven't switched to PHP 5 yet,
you can do this in the Control Panel.
But, again, you will not be able to
switch back to PHP 4 after switching
to PHP 5.
Here's how to switch from PHP 4 to PHP
5:
Log into the DreamHost Control Panel.
Click Domains, then Manage Domains.
Click the wrench icon next to the domain you want to activate PHP 5
on (under the Web Hosting column).
Select PHP 5.x.x from the dropdown menu.
Click Change fully hosted settings now! at the bottom of the
section.
Repeat steps 3-5 for each additional domain you want to
activate.
you could also check your php version with
<?php
phpinfo();
?>
The version required is PHP 5 or later. So theoretically your program should work.
If you can't get str_split to work, just use a string as an array:
$stuff = "abcdefghijkl";
echo $stuff[3];
will produce
d
This method is fastest, anyway. I don't know if it suits your needs, but if it does, I hope it helps!
Could be anything in your code. How do we know its not a 10 line script or 2000 line script?
You can use preg_split() to split an array into single characters, but it will return an extra empty string at the begining and the end.
$a = preg_split("//","abcdefg");
echo json_encode($a);
prints:
["","a","b","c","d","e","f","g",""]

Categories