简体   繁体   English

致命错误:未捕获的错误:找不到类“Func”php

[英]Fatal error: Uncaught Error: Class 'Func' not found php

My Questions is Find a 7 letter string of characters that contains only letters from我的问题是找到一个 7 个字母的字符串,其中只包含来自

acegikoprs acegikoprs

such that the gen_hash(the_string) is这样 gen_hash(the_string) 是

675217408078 675217408078

if hash is defined by the following pseudo-code:如果哈希由以下伪代码定义:

Int64 gen_hash (String s) {
    Int64 h = 7
    String letters = "acegikoprs"
    for(Int32 i = 0; i < s.length; i++) {
        h = (h * 37 + letters.indexOf(s[i]))
    }
    return h
}

For example, if we were trying to find the 7 letter string where gen_hash(the_string) was 677850704066, the answer would be "kppracg".例如,如果我们试图找到 gen_hash(the_string) 为 677850704066 的 7 个字母的字符串,答案将是“kppracg”。

Solution解决方案
test1.php测试1.php

I did that question solve in php, I am unable to run this code I am in php i don't have that much knowledge regarding php class and their function, Can any one solve this code and describe me.我在 php 中解决了这个问题,我无法运行此代码我在 php 中我对 php 类及其功能没有太多了解,任何人都可以解决此代码并描述我。 thanks in advance i will be very great full if anyone help me.提前致谢,如果有人帮助我,我会非常满意。

<?php

$set = "acdegilmnoprstuw";
$CONST_HASH = 7.0;
$CONST_MULT = 37.0;

$hash = new Func(function($string = null) use (&$CONST_HASH, &$CONST_MULT, &$set) {
  $_hash = $CONST_HASH;
  for ($i = 0.0; $i < get($string, "length"); $i++) {
    $_hash = _plus(to_number($_hash) * to_number($CONST_MULT), call_method($set, "indexOf", get($string, $i)));
  }
  return $_hash;
});

$decode = new Func(function($_hash = null) use (&$CONST_MULT, &$Math, &$set) {
  $decoded = ""; $positionsInSet = new Arr();
  for ($i = 0.0; $_hash > $CONST_MULT; $i++) {
    set($positionsInSet, $i, call_method($Math, "floor", (float)(to_number($_hash) % to_number($CONST_MULT))));
    $_hash /= 37.0;
  }
  for ($i = to_number(get($positionsInSet, "length")) - 1.0; $i >= 0.0; $i--) {
    $decoded = _plus($decoded, get($set, get($positionsInSet, $i)));
  }
  return $decoded;
});

I realize that this question was asked well over a year ago and I'm only just stumbling on it right now but seeing as there hasn't been an answer I figured I'd answer it.我意识到这个问题在一年前就被问到了,我现在只是在绊倒它,但看到没有答案,我想我会回答它。


You used a third party JavaScript to PHP converter utility and expected the demo to work out of the box.您使用了第三方JavaScript 到 PHP 转换器实用程序,并希望演示开箱即用。 You should have read up on it's usage as it clearly states in the ReadMe.md that, ...this tool is using esprima JavaScript parser with rocambole to walk the AST and escope to figure out the variable scope, hoist function declarations and so on...您应该已经阅读了它的用法,因为它在ReadMe.md中明确指出, ...这个工具使用esprima JavaScript 解析器和rocambole来遍历 AST 和escope以找出变量范围、提升函数声明等...

The developer goes on to say, After AST manipulation tools/codegen.js generates the PHP code by walking the tree.开发人员继续说,在 AST 操作tools/codegen.js之后,通过遍历树来生成 PHP 代码。 Now here's where it gets good.现在这就是它变好的地方。 Pay attention now..现在注意..

Various constructs get wrapped in helper functions, for instance, property access, method calls and + operator.各种构造都包含在辅助函数中,例如,属性访问、方法调用和+运算符。 The runtime helpers can be found in php/helper and there are a bunch of classes in php/classes for Array, RegExp and such.运行时助手可以在php/helper找到,在php/helper classes 中有很多php/classes用于 Array、RegExp 等。 All this PHP gets packaged into your output file, or you can save it to a standalone runtime and reference that from your output file like so:所有这些 PHP 都会打包到您的输出文件中,或者您可以将其保存到独立运行时并从您的输出文件中引用它,如下所示:

js2php --runtime-only > runtime.php
js2php --runtime runtime.php example.js > example.php

You can also specify the output file using -o or --out and you can compile multiple input files into one output file like so:您还可以使用-o--out指定输出文件,您可以将多个输入文件编译为一个输出文件,如下所示:

js2php -o example.php file1.js file2.js

So as you can see my friend, to get your code to work you merely need to include the runtime helpers functions so your converted script can be interpreted.因此,正如您所看到的,我的朋友,要使您的代码工作,您只需要包含运行时助手函数,以便可以解释您转换后的脚本。 I'm not sure as to which files it'll take to get your script to parse correctly, however now that I've pointed you in the right direction I'm confident you'll be able work it out yourself.我不确定要让您的脚本正确解析需要哪些文件,但是现在我已经为您指明了正确的方向,我相信您可以自己解决。

Happy coding.. =)快乐编码.. =)

Instead of assigning the inline function with new operator to variable, create a separate functions encode and decode where you can do the hashing and matching the hash code.不要将带有new运算符的内联函数分配给变量,而是创建一个单独的函数编码解码,您可以在其中进行散列和匹配散列代码。

Let me give you the snippet of how to do it.让我给你一个如何做到这一点的片段。 I am assuming that your using plain PHP.我假设您使用的是纯 PHP。

/* Call to function encode which returns you the encoded value and store in $encode variable */

$encode = encode($par1, $par2);

/* Call to function decode which returns you the decoded value and store in $decode variable */

$decode = decode($par1, $par2);

/* Function to encode your code */
function encode($par1, $par2){
    return $encode_value
}

/* Function to decode your code */
function decode($par1, $par2){
    return $decode_value
}

I have written this in Javascript to generate both Hash String and Number我已经用 Javascript 编写了这个来生成哈希字符串和数字

<!DOCTYPE html>
<html>
<body>

<p id="demo"></p>

<script>

var gen = gen_hash('kppracg');
document.write("kppracg hash value is ", gen);

document.write('<br><br>');

var gen = gen_hash('iorocks');
document.write("iorocks hash value is ", gen);


var hash = 675217408078;
var gen_rev = gen_hash_rev(hash);

document.write('<br><br>');

document.write("675217408078 hash value is ", gen_rev);


function gen_hash(s) {
    var h = 7;  
    var acegikoprs = "acegikoprs";
    for(var i = 0; i < s.length; i++) {
        h = (h * 37 + acegikoprs.indexOf(s[i]));
    }
    return h;
}


function gen_hash_rev(hash) {

    var arr_values = ['a','c','e','g','i','k','o','p','r','s'];
    var min = 0;
    var max  = 99999999;

        while (min <= max) {
            var final_result = "";
            var tempInt = parseInt(((max - min) / 2) + min);
            var arr_tempInt = num_array(tempInt);
            for(var i = 0; i < arr_tempInt.length; i++) {
                final_result = final_result + arr_values[arr_tempInt[i]];
            }
            var result = gen_hash(final_result);
            if(result < hash) {
                 min =  tempInt + 1;
            }
            else if( result >  hash) {
                 max =  tempInt - 1;
            }
            else {
                return final_result;
            }
        }
}

function num_array(num){

    var  output = [],
    sNumber = num.toString();

    for (var i = 0, len = sNumber.length; i < len; i += 1) {
        output.push(+sNumber.charAt(i));
    }
    return output;

}

</script>

</body>
</html>


声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 PHP致命错误:未捕获错误:找不到类 - PHP Fatal error: Uncaught Error: Class not found PHP致命错误:未捕获错误:找不到类'Facebook \ WebDriver \ ChromeOptions' - PHP Fatal error: Uncaught Error: Class 'Facebook\WebDriver\ChromeOptions' not found PHP致命错误:未捕获错误:未在中找到类“ ZipArchive” - PHP Fatal error: Uncaught Error: Class 'ZipArchive' not found in PHP的致命错误:未捕获的错误:类“路由器”中找不到 - php Fatal error: Uncaught Error: Class 'Router' not found in 严重错误:未捕获的错误:未找到类“缓存”-PHP - Fatal error: Uncaught Error: Class 'cache' not found - PHP PHP 致命错误:未捕获错误:Class 未找到异常 - PHP Fatal error: Uncaught Error: Class Exception not found PHP致命错误:未捕获错误:未找到类“ Api” - PHP Fatal error: Uncaught Error: Class 'Api' not found PHP致命错误:未捕获的错误:找不到类&#39;SoapClient&#39; - PHP Fatal error: Uncaught Error: Class 'SoapClient' not found xampp和PHP致命错误:未捕获的错误:未找到类“ DOMDocument” - xampp and PHP Fatal error: Uncaught Error: Class 'DOMDocument' not found PHP致命错误:未被捕获的错误:找不到类“ CakeTestSuite” - PHP Fatal error: Uncaught Error: Class 'CakeTestSuite' not found in
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM