草庐IT

numeric_traits_integer

全部标签

php - 如何在 laravel 中为所有模型使用 common Trait 实现 Eloquent 事件

我正在使用laravel5.4创建一个网络应用程序。我创建了一个特征来实现创建、更新、删除和恢复的Eloquent事件。我创建了一个trait如下:Auth::user()->id,'content_id'=>$model->id,'content_type'=>get_class($model),'action'=>static::getActionName($eventName),'description'=>ucfirst($eventName)."a".$reflect->getShortName(),'details'=>json_encode($model->getDirt

PHP 数组 : integer index vs string index

PHP数组的整数索引和字符串索引有什么区别吗(当然除了后者叫做associativearray)?例如,下面两个数组有什么区别:$intIndex[5]="Hello";$intIndex[6]="World";$intIndex[7]="!";和$strIndex['5']="Hello";$strIndex['6']="World";$strIndex['7']="!";在第一种情况下,$intIndex[0]到$intIndex[4]会怎样? 最佳答案 来自themanual(强调我的):Thekeycaneitherbean

php - Stripe 400 错误 "Invalid Positive Integer"

我有一个真正的问题。我正在尝试为一个通过Stripe向人们收费的非营利组织建立一个捐赠页面。我尝试进行的每一次收费都会给我一个错误,内容如下:已解析的请求帖子正文{"card":"TOKENWASHERE","description":"Donationby()","amount":"0","currency":"usd"}响应正文:{"error":{"type":"invalid_request_error","message":"Invalidpositiveinteger","param":"amount"}}我认为我传递给Stripe的金额有问题(显然Stripe认为它收到的

php - If 条件 : Why turning a boolean into an integer?

我看到了这样的情况:if((int)method_exists($this,$this->endpoint)>0)这背后是什么?与明显相比有什么优势if(method_exists($this,$this->endpoint))?(来源:http://coreymaynard.com/blog/creating-a-restful-api-with-php/) 最佳答案 我看不出将它变成整数有什么好处。因为method_exists已经返回一个bool值。这是一种冗长且无用的编码方式。如果语句需要一个bool值,并且method_e

php - Laravel: Trait method guard 没有被应用,因为与 App\Http\Controllers\Auth\AuthController 上的其他 trait 方法有冲突

我正在更新到Laravel5.4并收到此错误消息:Traitmethodguardhasnotbeenapplied,becausetherearecollisionswithothertraitmethodsonApp\Http\Controllers\Auth\AuthController这是我的AuthController类。middleware($this->guestMiddleware(),['except'=>['getLogout']]);}/***Getavalidatorforanincomingregistrationrequest.**@paramarray$d

php - Boolean和Integer是序列化后的字符串

我正在使用WordPressupdate_post_meta像这样保存一个数组$obj=array('array'=>array(1,'zwei',!!3),'string'=>'abc','bool'=>true,'bool2'=>false,'integer'=>1,'integer2'=>17);update_post_meta($post_ID,'my-key',$obj);但是如果我检查我得到的原始字段a:6:{s:5:"array";a:3:{i:0;i:1;i:1;s:4:"zwei";i:2;s:1:"1";}s:6:"string";s:3:"abc";s:4:"bo

php - JSON 架构 : how to allow empty string for property with numeric type?

在属性定义中我需要允许数字或空字符串值,这个表达式是否适合这个目的?"tprice":{"type":["number",{"enum":[""]}]}我用来验证数据的库(Jsv4)为空字符串生成错误:Invalidtype:string当我尝试为此属性设置零长度字符串时。 最佳答案 我认为适合您的解决方案是在架构中使用anyOf。这是适合您的模式:{"$schema":"http://json-schema.org/draft-04/schema#","properties":{"tprice":{"anyOf":[{"type"

PHP float 错误 : PHP Hangs On Numeric Value

我刚刚读了一篇关于php卡在某些float上的有趣文章,请参阅TheRegister和ExploringBinary.我从不明确使用float,我使用number_format()来清理我的输入并显示价格示例。此外,据我所知,所有来自例如表单的输入都是字符串,除非我告诉他们否则,所以我假设这个问题不会影响我。我说得对吗,或者我是否需要检查我服务器上的Wordpress和Squirrelmail安装,看看它们是否转换任何内容以float?或者更好的方法是,grep我服务器上的所有php文件用于float? 最佳答案 缓解问题的方法:使

类实现接口(interface)时PHP Trait冲突

我有一个实现execute方法接口(interface)的类。接口(interface)强制execute方法有两个带有一些类型提示的参数。我还使用了一个具有execute方法的特征,但具有不同的功能和签名。我通过使用更改特征方法名称:classMyClassimplementsMyInterface{useMyTrait{executeasprotectedcommanderExecute;}publicfunctionexecute(SomeInterface$arg1,SomeInterface2$arg2){//dosomething}}当我尝试运行该应用程序时,它会抛出一个f

php - Symfony/学说 : Why my integer Entity attribute is returning as string?

我有一个实体,其属性定义如下:/***@varinteger**@ORM\Column(name="weight",type="integer")*/private$weight;我试图解决一个错误并使用var_dump()来了解正在发生的事情......响应是:string'20'(length=2)我不明白为什么$weight作为字符串返回...它不应该是一个整数吗?int20或者我应该在我的业务逻辑中处理它吗?编辑(我如何调用var_dump()):我有一个名为“Calculator”的类,它迭代$items并使用$weight属性。是这样的:Controller:$calcul